

#ARDUINO ANALOGWRITE DISABLE CODE#
If setting a pin HIGH or LOW succeeds or fails depending on a something done a thousand lines of code earlier, perhaps in a function written by someone else, bugs will be essentially impossible to diagnose.ġ: Basic functions should cause as few side effects as possible. The Due board incorporates a sophisticated CPU, and people will write sophisticated and complex code for it. Here is the Arduino 1.5 version of turnOffPWM static void turnOffPWM(uint8_t timer)Ĭase TIMER1A: cbi(TCCR1A, COM1A1) break Ĭase TIMER1B: cbi(TCCR1A, COM1B1) break Ĭase TIMER0A: cbi(TCCR0A, COM0A1) break Ĭase TIMER0B: cbi(TCCR0A, COM0B1) break Ĭase TIMER2A: cbi(TCCR2A, COM2A1) break Ĭase TIMER2B: cbi(TCCR2A, COM2B1) break Ĭase TIMER3A: cbi(TCCR3A, COM3A1) break Ĭase TIMER3B: cbi(TCCR3A, COM3B1) break Ĭase TIMER3C: cbi(TCCR3A, COM3C1) break Ĭase TIMER4A: cbi(TCCR4A, COM4A1) break Ĭase TIMER4B: cbi(TCCR4A, COM4B1) break Ĭase TIMER4C: cbi(TCCR4A, COM4C1) break Ĭase TIMER4D: cbi(TCCR4C, COM4D1) break Ĭase TIMER5A: cbi(TCCR5A, COM5A1) break Ĭase TIMER5B: cbi(TCCR5A, COM5B1) break Ĭase TIMER5C: cbi(TCCR5A, COM5C1) break ĭigital_pin_to_timer_PGM has all the necessary information but I can't find its definition for DUE on my Arduino 1.5, which has DUE listed. If (timer != NOT_ON_TIMER) turnOffPWM(timer) To test my theory, I have to read some code that deals with registers But this behavior of the analogWrite() and digitalWrite() seems to be a serious problem that should be addressed.

I have modified the robot code successfully. See the attachment for an example of motor driving code (for the Solarbotics Brutusbot robot) that works for the Uno board, but not for the Due board. The reason I ask this question is that such behavior is not only non-intuitive, but also breaks many lines of useful existing code. However, the following works with both boards:ĭoes the Due not allow a call to digitalWrite if analogWrite has already been called? With the Arduino 1.5 software, the following code blinks an LED using the Uno board, but not with the Due:
