On my Arduino Mega, I'm trying to create a very simple Interrupt. Basically every time a button is pressed I want the interrupt to be triggered, and increment a counter. My code is quite simple..
volatile unsigned long counter;
void buttonPulse()
{
counter++;
}
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 20; // the number of the pushbutton pin
const int IRQ = 3; // According to the web page on a Mega, Pin 20 is IRQ 3
void setup() {
Serial.begin(9600);
counter = 0;
attachInterrupt(IRQ,buttonPulse,RISING);
Serial.println("Enter to continue");
while (!Serial.available()); Serial.flush();
}
void loop(){
delay(200);
Serial.print("Counter=");Serial.println(counter);
}
I have the button wired with 5v on one leg, and the other leg connected to Pin 20 (which should be IRQ 3 on a Mega.
My interrupt never triggers when i press the button.
