Skip to content

Instantly share code, notes, and snippets.

@apotox
Created June 27, 2020 18:43
Show Gist options
  • Save apotox/be6a8fda2618f59c4dc35101fd056bb6 to your computer and use it in GitHub Desktop.
Save apotox/be6a8fda2618f59c4dc35101fd056bb6 to your computer and use it in GitHub Desktop.
attachInterrupt example for the atmega328
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;
}
@apotox
Copy link
Author

apotox commented Jun 27, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment