Because the response to a RISING and FALLING need to be different.
I can do this by keeping a "state" boolean that changes on every CHANGE interrupt but I was hoping for a cleaner way.
Here's the code for this but still curious if a better solution exist:
boolean pushed = false;
int pin_interrupt = 2;
int pin_led = 13;
void setup() {
Serial.begin(9600);
attachInterrupt(0, interrupt_handler, CHANGE);
pinMode(pin_led, OUTPUT);
pinMode(pin_interrupt, INPUT);
if(digitalRead(pin_interrupt)){
pushed = true;
Serial.println("WARNING: switch was pushed during startup");
} else {
Serial.println("Switch state was normal during startup");
}
}
void interrupt_handler() {
pushed = !pushed;
if (pushed){
// do my "button pushed" things
} else {
// do my "button released" things
}
}
void loop()
{
digitalWrite(pin_led, pushed);
}