Skip to content

Add note re: contact bounce to attachInterrupt reference #575

Open
@per1234

Description

@per1234

Moved from arduino/Arduino#8711 by @Omar-alSuntawi

This code does not work correctly !

const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}

void loop() {
  digitalWrite(ledPin, state);
}

void blink() {
  state = !state;
}

which is on the Arduino Reference https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

It seems to accidentally read random values.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions