/*
* A program which changes the state of 3 external LEDs
* - In the low state
* - Rising edge
*
* SYNTAX: attachInterrupt(interrupt, ISR, mode)
* interrupt: the number of the interrupt. Allowed data types: int.
* ISR: the ISR to call when the interrupt occurs; this function must take no parameters and return nothing.
* This function is sometimes referred to as an interrupt service routine.
* mode: defines when the interrupt should be triggered. Four constants are predefined as valid values:
* - LOW to trigger the interrupt whenever the pin is low,
* - CHANGE to trigger the interrupt whenever the pin changes value
* - RISING to trigger when the pin goes from low to high,
* - FALLING for when the pin goes from high to low.
*/
int LedPin1 = 8;
int LedPin2 = 9;
int LedPin3 = 10;
volatile int state = LOW; // state is changed in the ISR , hence declared as volatile.
void setup()
{
pinMode(LedPin1, OUTPUT); // set to output
pinMode(LedPin2, OUTPUT); // set to output
pinMode(LedPin3, OUTPUT); // set to output
attachInterrupt(1, blink, CHANGE); // turns on interrupt on digital pin 3 with MODE=CHANGE
//attachInterrupt(1, blink, LOW); // turns on interrupt on digital pin 3 with MODE=LOW
//attachInterrupt(1, blink, RISING); // turns on interrupt on digital pin 3 with MODE=RISING
//attachInterrupt(1, blink, FALLING); // turns on interrupt on digital pin 3 with MODE=FALLING
// ISR named blink
}
void loop()
{
digitalWrite(LedPin1, state);
digitalWrite(LedPin2, state);
digitalWrite(LedPin3, state);
}
void blink() // ISR whenever digital pin 3 changes.
{
state = !state;
}