Hi All,
I am doing my first arduino project which is to use an IR remote to control an RC car I am building. At the moment I am testing to see if I can use an IR remote to send power to an different LEDs while I hold down one of the buttons on the remote. I will later replace the LEDs with motors but for now am just testing.
My problem is that whenever I press a button on the remote - the LED stays on and does not go off when I release the button and in addition when I press a button to light up one LED it stays on and nothing happens when I press a different button.
Any advice on code/approach will be a big help!
Thanks
#include "IRremote.h"
#include "IR.h"
#define LED1 3
#define LED2 5
#define LED3 9
#define LED4 10
IRrecv irrecv(RECEIVER); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
void setup() {
Serial.begin(9600);
Serial.println("IR Receiver Button Decode");
irrecv.enableIRIn();
pinMode (LED1, OUTPUT);
pinMode (LED2, OUTPUT);
pinMode (LED3, OUTPUT);
pinMode (LED4, OUTPUT);
}
void loop()
{
if (irrecv.decode(&results))
{
while (keyValue[0] == results.value)
{
digitalWrite (LED1, HIGH);
}
while (keyValue[1] == results.value)
{
digitalWrite (LED2, HIGH);
}
while (keyValue[2] == results.value)
{
digitalWrite (LED3, HIGH);
}
while (keyValue[3] == results.value)
{
digitalWrite (LED4, HIGH);
}
irrecv.resume();
}
}