Skip to content

digitalWrite and analogWrite do not work in combination #280

Closed
@khanning

Description

@khanning

If you call analogWrite on a PWM capable pin with any value other than 0 and 255, any subsequent calls to digitalWrite on the same pin are ignored until one of the following events occurs:

  1. pinMode(PIN, OUTPUT) is called on the pin again
  2. You call analogWrite(PIN, 0) or analogWrite(PIN, 255)

This behavior does not occur on the Arduino UNO.

Here is a simple sketch that illustrates the issue:

void setup() {
  pinMode(9, OUTPUT);
}

void loop() {
  digitalWrite(9, HIGH);
  delay(1000);
  analogWrite(9, 255/2);
  delay(1000);
  digitalWrite(9, LOW);
  delay(1000);
}

On the 101
Once analogWrite(9, 255/2) is called, pin 9 remains at a 50% duty cycle, ignoring all subsequent digitalWrite commands.

On the UNO
Pin 9 successfully switches between 100%, 50%, and 0% duty cycle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions