Skip to content

digitalWrite(LED_BUILTIN,0) has inverted logic #2579

@FabioM3

Description

@FabioM3

Describe the bug
The logic on "digitalWrite(LED_BUILTIN, 0)" is inverted, when I use an external led it works, but for the LED_BUILTIN it turns OFF the led with 1 and ON with 0.

To Reproduce

`#define botaoLigaDesliga A3
short ligado = 0;
unsigned long tempoPassadoBotao = 0;

void setup() {
pinMode(botaoLigaDesliga, INPUT_PULLDOWN);
pinMode(LED_BUILTIN, OUTPUT);

digitalWrite(LED_BUILTIN, ligado);
}

void loop() {
if (digitalRead(botaoLigaDesliga)) {
if (millis() - tempoPassadoBotao >= 2000) {
if (ligado) {
ligado = 0;
} else {
ligado = 1;
}

  digitalWrite(LED_BUILTIN, ligado);
  tempoPassadoBotao = millis();
  Serial.print("Botão apertado - ");
  Serial.println(ligado);
}

}
}`

Steps to reproduce the behavior:

  1. Plug.
  2. Press BTN on A3 to change the state of the led.
  3. See on serial the 0 or 1 and compare with the led.

Expected behavior
The led needs to be OFF with 0 and on with 1.

Desktop (please complete the following information):

  • OS: Windows 10
  • Arduino IDE version: [e.g. 2.3]
  • STM32 core version: [e.g. 2.9]

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions