Open Nilloc opened 11 years ago
This is an obscure issue since there is typically no reason to use digitalWrite() and analogWrite()/pwmWrite() on the same pin in the same sketch.
The problem comes from the fact that digitalWrite() no longer (compared to previous versions) clears the the PWM mode for the pin.
This was chosen for optimization reasons (i.e. to reduce the digitalWrite() to a single machine instruction if using a constant for the pin number.)
However, as we move forward, it will make more sense to be thorough instead of optimal.
A fix for this problem is to clear the output mode for the given pin in its associated timer at the start of digitalWrite().
This applies to the AVR8Bit core only.
Fix forthcoming.
The following sketch causes the LED to go fully bright, then dim (analogWrite(50)) then stay dim, never returning to 5 volts.
The sketch does work as expected in the Arduino 1.0.1 IDE.
Tested using a Sparkfun Redboard and a 2.7v LED.