// Declare as volatile any blinkDelayiables that you modify
// within the interrupt function.
volatile int blinkDelay;
static unsigned long past; // milis
unsigned long now; // milis
void setup() {
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(6, OUTPUT);
//LOW to trigger the interrupt whenever the pin is low
//CHANGE to trigger the interrupt whenever the pin changes value
//RISING to trigger when the pin goes from low to high
//FALLING for when the pin goes from high to low
attachInterrupt(digitalPinToInterrupt(2), green_button, FALLING);
attachInterrupt(digitalPinToInterrupt(3), red_button, FALLING);
Serial.begin(9600);
Serial.println("BEGIN");
Serial.println();
blinkDelay=500;
}
void loop() {
Serial.println(blinkDelay);
now=millis();
if (now-past>=blinkDelay) {
digitalWrite(6, !digitalRead(6));
past=now;
}
}
void green_button() {
blinkDelay=500;
Serial.println(blinkDelay);
}
void red_button() {
blinkDelay=3000;
Serial.println(blinkDelay);
}