Skip to content

digitalWrite ignored after calling analogWrite on PWM pin #385

Open
@don

Description

@don

Calls to digitalWrite don't do anything after calling analogWrite on a PWM pin. Tested on the MKR1000 and MKR WiFi 1010 with SAMD 1.6.20 core.

const int ledPin = 5;
unsigned long wait = 10 * 1000;
bool analog = false;

void setup() {
  Serial.begin(9600);

  // Comment the next line to NOT wait for a serial connection for debugging
  while (!Serial);

  // initialize digital pin 5 as an output.
  pinMode(ledPin, OUTPUT);

  digitalWrite(ledPin, HIGH);
  Serial.println("Blinking with digitalWrite");
}

void loop() {
  Serial.println("on");
  digitalWrite(ledPin, HIGH);
  delay(1000);
  Serial.println("off");
  digitalWrite(ledPin, LOW);
  delay(1000);

  if (millis() > wait && !analog) {
    Serial.println("analogWrite will break sketch");
    analogWrite(ledPin, 0xF);
    analog = true;
  }
}

The Arduino 101 had a similar issue that was fixed arduino/ArduinoCore-arc32#280

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions