Interrupt problem (noob)

Hi, I'm trying to learn how interrupt works, but it didn't work for me. I have a mega2560 and I connected a button to the digital pin 2 (INT4) as it seems on this pic: http://arduino.cc/en/uploads/Tutorial/button_schem.png

My source code is this:

volatile int count = 0;

void setup() {  
  Serial.begin(9600);
  attachInterrupt(4, inc, RISING);
}

void inc(){
  count++;
}

void loop(){
  Serial.print(count);
  Serial.write('\n');
  delay(400);
}

It is not working. The count variable is always 0. Maybe this circuit is bad for this? I know about the debouncing, but in this test I didn't care about it.

From the reference for attachInterrupt(): “Most Arduino boards have two external interrupts: numbers 0 (on digital pin 2) and 1 (on digital pin 3). The Arduino Mega has an additional four: numbers 2 (pin 21), 3 (pin 20), 4 (pin 19), and 5 (pin 18).”

You are using Interrupt 4 so is your button on Pin 19?

Oh, Thank You. Sorry for I wasn't paying attention when I read the reference. Then I have another question. How can I know which interrupt is detected asynchronously? In atmega2560 these are INT0,INT1,INT2,INT3. I want to wake up the arduino from sleep.

Xypista:
How can I know which interrupt is detected asynchronously?

I’m not sure I understand the question.

On the ATmega2560 the external interrupts 0 through 7 can wake the processor from sleep but for interrupts 4 though 7 you have to use a level-triggered interrupt (LOW or HIGH) and not an edge-triggered interrupt (RISING or FALLING).

There is no HIGH interrupt. The four states are LOW, CHANGE, RISING, FALLING.

To wake from sleep you need to use LOW.

Although maybe for interrupts 4 to 7 CHANGE is a level interrupt, the documentation is a bit unclear.