Hello,
I want to make a timer activated by an IR sensor with millis(). When I activate the sensor, after one second, r change value.
Without sensor it’s work ok, but with the sensor r does not change the value
#include<IRremote.h>
int Recv_PIN = A0;
IRrecv irrecv(Recv_PIN);
decode_results results;
int r = 0;
unsigned long previousMillis;// will store last time LED was updated
const int interval = 1000;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop(){
Serial.println(r);
if (irrecv.decode(&results)){
if(results.value==0xFF18E7)
{
unsigned long currentMillis = millis();
if ((unsigned long)(currentMillis - previousMillis) >= interval){
r=1;
previousMillis = currentMillis;
}
}
}
}
What I need to change?