Created
December 9, 2014 13:59
-
-
Save extrasleepy/e120be94dccda907a206 to your computer and use it in GitHub Desktop.
This file contains 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
// This sketch demonstrates INPUT_ PULLUP and Interrupts | |
int ledPin = 7; | |
volatile boolean flashy = false; //necessary declaration for passing adjusting global variables with interrupts | |
void setup() | |
{ | |
pinMode(ledPin, OUTPUT); | |
pinMode(2, INPUT_PULLUP); | |
attachInterrupt(0, interruption, FALLING); //attaches interrupt to Digital 2 with internal pull-up resistor | |
} | |
void loop() | |
{ | |
int period = 5000; | |
if (flashy) period = 50; | |
digitalWrite(ledPin, HIGH); | |
delay(period); | |
digitalWrite(ledPin, LOW); | |
delay(period); | |
} | |
void interruption() //interrupt function | |
{ | |
flashy = ! flashy; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment