digitalWrite doesn't work after analogWrite on the same pin

pixelk

Well-known member
Unlike on vanilla arduino digitalWrite doesn't work after analogWrite, you cant set a pin to HIGH or LOW after using analogWrite(pin,value) on it.
 
Yes, analogWrite is putting the pin into a different mode, which digitalWrite can't use. I'll work on digitalWrite next week.
 
Digging up an old thread.

I have a sketch that needs to turn a pin full on (digitalWrite) then in another mode, it needs to be a PWM (analogWrite). It worked on an Arduino, but analogWrite happens later in the code, after it has already been digitalWritten and any PWM value in analogWrite results in full on (3v3).

How do I mix these 2 modes? I do not understand the example snippet? Do I define the pin again every time I need to switch modes between analopgWrite and digitalWrite? Do I need to define the frequency or is there a default value similar to previous arduino?

Keith
 
I don't know if it wasn't fixed in a recent update, but the sketch I'm working on does exactly that (define the pin again every time I need to switch modes) to address this issue (which may or may not be corrected since). I never changed PWM frequency, but I know it can be done in the latest teensyduino releases.
 
Yup, this is still a problem.

Tested with Arduino IDE 1.0.5 and 1.6.1, on a Teensy 3.1, using Teensy Loader 1.21.

Ok, it's probably a low-priority problem given that there's a bearable work-around, but I'm hoping it's helpful to flag such unexpected behaviour.
 
This just got me. Is there any reason to redefine the pin to turn the output off? I was using digitalWrite(pin,LOW), which didn't work so I tried analogWrite(pin,0), which did. That seems fine but I just want to make sure there's no reason to do something different.
 
Back
Top