I'm exploring a little bit, and want to use more than two interrupts. The software keyword 'attachInterrupt' supports INT0 and INT1. Apparently you can use 'ISR(interrupt)' to handle additional interrupts. Since I have an NG board with a Mega168, I found that PCINT0 is my likely choice; it's punched out thru digital pin 8. So I threw together a test, which I hoped would ramp up an LED each time I press a button, using PWM.
Here I connect an LED to pin 9, which is one of the PWM ports, and a button on digital pin 8, which corresponds to PCINT0 (I double-checked the arduino refs against the 168 datasheet, and triple-checked with my meter).
volatile int count = 0;
volatile int ledpin = 9;
volatile int setpin = 8;
ISR(PCINT0_vect)
{
count = count + 1;
}
void setup()
{
pinMode(setpin, INPUT);
}
void loop()
{
analogWrite(ledpin,count);
if (count == 255) count = 0;
}
But I find it doesn't work as I had hoped. Is there anything I am missing, doing wrong? Thank you.