Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Last active July 6, 2020 23:31
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 JeffersGlass/27cbbfae209b5249c651fdc724834ea5 to your computer and use it in GitHub Desktop.
Save JeffersGlass/27cbbfae209b5249c651fdc724834ea5 to your computer and use it in GitHub Desktop.
const int buttonPin = 2;
const int ledPin = 9;
volatile int countdown = 0;
void setup() {
// put your setup code here, to run once:
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(2), setState, FALLING);
}
void loop() {
analogWrite(ledPin, countdown);
countdown = max(countdown-10, 0);
delay(100);
}
void setState(){
countdown = 255;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment