Skip to content

Unexpected digitalWrite behavior when writing numerical values 4 and 2 #145

@SaltlessLemons

Description

@SaltlessLemons

Using digitalWrite(pin, 0b10) sets the pin high as expected unless it is preceded by a digitalWrite(pin, 0b100), in which case writing 0b10 actually sets the pin low. Subsequent writes (including reattempting to write 0b10) behave as expected.

Recreated in a new blank sketch, using an UNO Wifi R2 and Arduino IDE 2.3.6

#define PIN_LED 25 //Wifi R2 built-in LED is on pin 25

void setup() {
  //digitalWrite weird behaviour test
  pinMode(PIN_LED, OUTPUT);
  delay(2000);
  digitalWrite(PIN_LED, 0b100);
  delay(1000);
  digitalWrite(PIN_LED, 0b10); //LED Turns off here; removing the above write causes this write to behave as expected
  delay(1000);
  digitalWrite(PIN_LED, 0b1);
}

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

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions