Arduino Forum

Products => MKR Boards => MKRWAN1300 => Topic started by: gerrikoio on Dec 22, 2018, 06:45 pm

Title: analogWrite not switching to digitalWrite
Post by: gerrikoio on Dec 22, 2018, 06:45 pm
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:

}
Title: Re: analogWrite not switching to digitalWrite
Post by: MartinL on Dec 27, 2018, 10:55 am
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.
Title: Re: analogWrite not switching to digitalWrite
Post by: gerrikoio on Dec 28, 2018, 08:20 pm
Thanks, adding the pinMode again worked.