// Press fast, blink slow.
int ledPin = 6;
int buttonPin = 2;
volatile unsigned int buttonPresses = 0;
void buttonPressedISR ()
{
buttonPresses++;
}
void setup()
{
//Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
attachInterrupt(digitalPinToInterrupt(buttonPin), buttonPressedISR, FALLING);
}
void loop()
{
bool blink = false; // default false
// Blink maximum once, each time the loop() runs.
noInterrupts();
if(buttonPresses > 0)
{
buttonPresses--;
blink = true;
}
interrupts();
if(blink)
{
digitalWrite(ledPin,HIGH);
delay(300);
digitalWrite(ledPin,LOW);
delay(300);
}
}