Interrupt on Pin 4 (PCINT20)

Hi. I need to detect a HIGH interrupt on PIN 4 of an arduino uno. I have used this code which works fine with PIN9 (PCINT1) but could not get it to work with PIN 4. I have a 10K pull up resistor to VCC and the LED is on PIN 13. Can you please help:

const byte ledPin = 13;
const byte interruptPin = 4;
volatile byte state = LOW;

ISR (PCINT0_vect)
{
state = !state;
// handle pin change interrupt for D8 to D13 here
} // end of PCINT0_vect

ISR (PCINT1_vect)
{
state = !state;
// handle pin change interrupt for A0 to A5 here
} // end of PCINT1_vect

ISR (PCINT2_vect)
{
state = !state;
// handle pin change interrupt for D0 to D7 here
} // end of PCINT2_vect

void setup ()
{
pinMode(ledPin, OUTPUT);
// pin change interrupt (example for D9)
PCMSK0 |= bit (PCINT20); // want pin 9
PCIFR |= bit (PCIF2); // clear any outstanding interrupts
PCICR |= bit (PCIE2); // enable pin change interrupts for D8 to D13
}

void loop(){
digitalWrite(ledPin, state);
}

OK Just realised I got this
PCMSK0 |= bit (PCINT20); // want pin 9

instead of this
PCMSK2 |= bit (PCINT20); // want pin 9

:slight_smile:

WORKING NOW. YAY :slight_smile: