Skip to content

Instantly share code, notes, and snippets.

@RyanFleck
Last active September 21, 2019 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanFleck/206b1f66981043d9d96b193cb9a3f288 to your computer and use it in GitHub Desktop.
Save RyanFleck/206b1f66981043d9d96b193cb9a3f288 to your computer and use it in GitHub Desktop.
Simple Interrupt
// Pin 13 has an LED connected on most Arduino boards.
const byte ledPIN = 13;
const byte interruptPIN = 2;
volatile boolean enabled;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(ledPIN, OUTPUT);
pinMode(interruptPIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPIN), first_ISR, FALLING);
enabled=true;
}
// the loop routine runs over and over again forever:
void loop() {
if(enabled)
digitalWrite(ledPIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a second
digitalWrite(ledPIN, LOW); // turn the LED off by making the voltage LOW
delay(100); // wait for a second
}
void first_ISR() {
if(enabled){
enabled=false;
}else{
enabled=true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment