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?
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.
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.