Skip to content

Instantly share code, notes, and snippets.

@extrasleepy
Created December 9, 2014 13:59
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 extrasleepy/e120be94dccda907a206 to your computer and use it in GitHub Desktop.
Save extrasleepy/e120be94dccda907a206 to your computer and use it in GitHub Desktop.
// 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