Do you understand why this work well:
Code: Select all
#include <Arduino.h>
#define LED 12
#define R1 27
#define NO 14
bool RUNNING = true;
bool TRIGGER = false;
void IRAM_ATTR NO_trigger()
{
if(!TRIGGER && RUNNING)
{
TRIGGER = true;
}
}
void setup()
{
pinMode(LED, OUTPUT);
pinMode(NO, INPUT_PULLUP);
attachInterrupt(NO, NO_trigger, RISING);
}
void loop()
{
while(RUNNING)
{
while(TRIGGER)
{
pinMode(R1, OUTPUT);
digitalWrite(LED, HIGH);
delay(200);
pinMode(R1, INPUT);
digitalWrite(LED, LOW);
TRIGGER = false;
}
}
}
Code: Select all
#include <Arduino.h>
#define LED 12
#define R1 27
#define NO 14
bool RUNNING = true;
bool TRIGGER = false;
void IRAM_ATTR NO_trigger()
{
if(!TRIGGER && RUNNING)
{
TRIGGER = true;
}
}
void setup()
{
pinMode(LED, OUTPUT);
pinMode(NO, INPUT_PULLUP);
attachInterrupt(NO, NO_trigger, RISING);
}
void loop()
{
while(RUNNING)
{
if(TRIGGER)
{
pinMode(R1, OUTPUT);
digitalWrite(LED, HIGH);
delay(200);
pinMode(R1, INPUT);
digitalWrite(LED, LOW);
TRIGGER = false;
}
}
}
Thanks!