Last active
September 21, 2019 21:39
-
-
Save RyanFleck/206b1f66981043d9d96b193cb9a3f288 to your computer and use it in GitHub Desktop.
Simple Interrupt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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