Go Down

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

gerrikoio

I am using an MKR WAN 1300 board.

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

Quote
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);
delay(5000);
digitalWrite(5, LOW);
}

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

}

MartinL

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.

gerrikoio

Thanks, adding the pinMode again worked.

Go Up