I use an Arduino Uno and already set it up to work with interrupts on digital pins 2, 3, 4 and 5 according to an explanation1 I found.
void setup()
contains the following code to setup the interrupts.
//Endable Interrupts for PCIE2 Arduino Pins (D0-7)
PCICR |= (1<<PCIE2);
//Setup pins 2,3,4,5
PCMSK2 |= (1<<PCINT18);
PCMSK2 |= (1<<PCINT19);
PCMSK2 |= (1<<PCINT20);
PCMSK2 |= (1<<PCINT21);
//Trigger Interrupt on rising edge
MCUCR = (1<<ISC01) | (1<<ISC01);
And now, the ISR( PCINT2_vect ) function is triggered on every interrupt. That works like a charm. My question is, what is the best/fastest way to find out, which pin was triggered?
I found something in Re: Is better to use ISR(PCINT2_vect) or attachInterrupt on pins 2, 3?, but I do not understand the code and it does not work out of the box. But it looks impressive...
What is the solution?
[2] http://arduino.cc/forum/index.php/topic,72496.15.html#lastPost
Edit:
At the moment, I am reading the pin state from the from the input pin register:
if (PIND & 0b00000100)
Serial.println( "PIN 2" );
if (PIND & 0b00001000)
Serial.println( "PIN 3" );
if (PIND & 0b00010000)
Serial.println( "PIN 4" );
if (PIND & 0b00100000)
Serial.println( "PIN 5" );
In the end, I want to count the interrupts on the pins. But how can I assure, that there are no counted twice?