Go Down

Topic: analogWrite not switching to digitalWrite (Read 873 times) previous topic - next topic


I am using an MKR WAN 1300 board.

According to the reference: https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/

After a call to analogWrite(), the pin will generate a steady square wave of the specified duty cycle until the next call to analogWrite() (or a call to digitalRead() or digitalWrite()) on the same pin.
In my case, when I use analogWrite it ignores my subsequent digitalWrite.

Here is my test case. It does not turn off my LED, which I have attached to pin 5.

Code: [Select]

void setup() {
// put your setup code here, to run once:
pinMode(5, OUTPUT);

analogWrite(5, 10);
digitalWrite(5, LOW);

void loop() {
// put your main code here, to run repeatedly:



Hi gerrikoio,

It's the pinMode() function that configures the pin back to digital GPIO.

Just place the line:

Code: [Select]
pinMode(5, OUTPUT);
...after the delay() function.


Thanks, adding the pinMode again worked.

Go Up