UNO R4 WIFI (Freenove version) - IDE 2.3.3. - Windows11
When I use a "attachInterrupt(digitalPinToInterrupt(IR_PIN)" it seems to create an interrupt.
In the following code the Serial.print produces an "1" i.e. an interrupt has been triggered even though the flag was preset to false.
if I enable the two lines:
//delay(50);
//IRflag = false;
then the printout will give me a "0" (false) however if i reduce the delay to any value less than 50 will get a "1"(true). which seems to infer that that attach instruction takes at least 40 milliseconds i.e. after the "IRflag = false;" instruction has taken place!
volatile bool IRflag = false;
void setup()
{
pinMode(IR_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(IR_PIN), IRfound, CHANGE);
}
void loop()
{
if (IRflag == true)
{
detachInterrupt(digitalPinToInterrupt(IR_PIN)); // I detach interrupt toprevent multiple interrupts during receipt of code
if (IrReceiver.decode())
{
//
// general code to analyse the decoded value from the IR Receiver
//
}
else if ((temp==0x1EA10000) // temp is decoded value from IR Receiver
{
do
{
IRflag = false;
attachInterrupt(digitalPinToInterrupt(IR_PIN), IRfound, CHANGE);
//delay(50);
//IRflag = false;
//
// additional testing code
//
Serial.println(IRflag);
if (IRflag == true)
{
break;
}
} while (testingflag == false);
}
}
}
void IRfound()
{
IRflag = true;
}