Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Debounced Switch Input
- */
- const int buttonPin = 2; // Button pin
- const int ledPin = 7; // LED pin
- int ledState = LOW;
- // variables will change:
- volatile int buttonState = 0; // Pushbutton Status Variable
- unsigned long previousMillis = 0; // Store last time LED was updated
- const long interval = 1000;
- void setup() {
- // initialize the LED pin as an output:
- pinMode(ledPin, OUTPUT);
- // initialize the pushbutton pin as an input:
- pinMode(buttonPin, INPUT);
- // Attach an interrupt to the ISR vector
- attachInterrupt(0, pin_ISR, CHANGE);
- }
- void loop() {
- // Nothing here!
- }
- void pin_ISR() {
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= interval) {
- // save the last time you blinked the LED
- previousMillis = currentMillis;
- // if the LED is off turn it on and vice-versa:
- if (ledState == LOW) {
- ledState = HIGH;
- } else {
- ledState = LOW;
- }
- // Set LED with the ledState of the variable
- digitalWrite(ledPin, ledState);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement