/* Program 6-1: Interrupts on an Arduino * SW1 is connected to pin 3 (interrupt 2) of Arduino * count up every time SW1 interrupts the main program */ const byte SW1 = 3; //SW1 is connected to interrupt of pin#3 volatile byte count = LOW; void setup() { pinMode(SW1, INPUT); //pin as input Serial.begin(9600); attachInterrupt(digitalPinToInterrupt(SW1), myISR, RISING); } void loop() { } //Interrupt Service Routine //Count up every time SW1 interrupts the main program void myISR() { count++; //count up upon pressing SW1 Serial.println(count); // Display count on Serial Monitor }