I would like to use the IR remote with Arduino to turn on a LED and turn off the same LED when I push on the remote.
That is to say :
- If I push on 1 I would like the LED turn on
- If I push on 2 I would like the LED turn off
Here is my code :
#include <IRremote.h>
const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
const int L1 = 13;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(L1, OUTPUT);
}
void loop(){
if (irrecv.decode(&results)){
unsigned int value = results.value;
Serial.println(value);
irrecv.resume();
if(value == 12495){
digitalWrite(L1, HIGH);
delay(1000);
}
else if(value == 6375){
digitalWrite(L1, LOW);
delay(1000);
}
}
}
But the problem is when I push on 1 I just see the LED turn on but very quickly the LED turns off then whereas I don't push on the button 2.
Could you help me please?
delay(1000);
after turning the led on/off.