Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const byte interruptLed = 13; // LED controlled by interrupt pin
- const byte blinkLed = 4; // LED to flash for interrupt testing
- int delayTime = 500; // Delay time for blinking LED
- const byte interruptPin = 2; // Button connected between here and GND
- // Set to 'volatile' to allow the ISR to change the variable
- volatile byte state = LOW; // State of interrupt LED.
- void setup()
- {
- pinMode(blinkLed, OUTPUT);
- pinMode(interruptLed, OUTPUT);
- pinMode(interruptPin, INPUT_PULLUP);
- // Mode: CHANGE -> on when button pushed. RISING -> Latches On
- attachInterrupt(digitalPinToInterrupt(interruptPin), blink, RISING);
- }
- void loop()
- {
- flash(blinkLed);
- digitalWrite(interruptLed, state);
- }
- //-------------------------------------------------------------------------
- // LED flash function
- void flash(byte pin)
- {
- digitalWrite(pin, HIGH);
- delay(delayTime);
- digitalWrite(pin, LOW);
- delay(delayTime);
- }
- //-------------------------------------------------------------------------
- // Interrupt Function (ISR)
- void blink()
- {
- state = !state;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement