Phew, finally got the buttons to be read reliably with interrupts in arduino IDE. No polling required, though we might want to elaborate on the debouncing at some point. This also means there are a lot more pins for doing external interrupts with than arduino allows "out of the box", though only pins 2&3 do RISING/FALLING, the rest are state change, not a big deal.
Code:
#include <avr/interrupt.h>
#include <avr/io.h>
int lbuttonPin = 17; // Left Button, on analog 3
int mbuttonPin = 18; // Middle Button, on analog 4
int rbuttonPin = 19; // Right Button, on analog 5
//button signals are inverted (internal pullup resistor), so true is not pressed
boolean lbutton = true;
boolean mbutton = true;
boolean rbutton = true;
//attach the interrupt
ISR( PCINT1_vect ){
PCICR &= !(1 << PCIE1);//disable interrupts in the interrupt
if (!digitalRead(lbuttonPin)) lbutton = false;
if (!digitalRead(mbuttonPin)) mbutton = false;
if (!digitalRead(rbuttonPin)) rbutton = false;
PCICR |= (1 << PCIE1);
}
void setup() {
Serial.begin(9600);
pinMode( lbuttonPin, INPUT );
pinMode( mbuttonPin, INPUT );
pinMode( rbuttonPin, INPUT );
//"turn on" the internal pullup resistors
digitalWrite( lbuttonPin, HIGH);
digitalWrite( mbuttonPin, HIGH);
digitalWrite( rbuttonPin, HIGH);
//low level interrupt stuff
PCICR |= (1 << PCIE1);
PCMSK1 |= (1 << PCINT11);
PCMSK1 |= (1 << PCINT12);
PCMSK1 |= (1 << PCINT13);
}
void loop() {
//print out what buttons have been pressed
if(!lbutton) Serial.print("lbutton");
Serial.print(",");
if(!mbutton) Serial.print("mbutton");
Serial.print(",");
if(!rbutton) Serial.print("rbutton");
Serial.println("");
//reset the buttons
lbutton = true;
mbutton = true;
rbutton = true;
delay(500);
}