unsigned long previousMillis; // timestamp
bool enable = false; // enable the millis-timer
volatile bool pulse = false; // variable to send information to the loop()
void blink()
{
pulse = true;
}
void setup()
{
pinMode(2, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
attachInterrupt(digitalPinToInterrupt(2), blink, FALLING);
}
void loop()
{
unsigned long currentMillis = millis();
if( pulse)
{
digitalWrite( LED_BUILTIN, HIGH);
previousMillis = currentMillis;
enable = true;
pulse = false;
}
if( enable)
{
if( currentMillis - previousMillis >= 200) // stretch to 200ms
{
digitalWrite( LED_BUILTIN, LOW);
enable = false;
}
}
}