I am playing around with an IR sensor on an Arduino and made a simple program to light some LEDs from my TV remote. I have a Red, Green and yellow LED connected and a red, green and yellow button on the remote to operate each one, this works fine.
What I want to be able to do firstly is to be able to press the red button and instead of the red LED just turning on, it would start flashing and stop again when the button is pressed again, with the other (green and yellow) buttons also working as normal. I am very new to this and would appreciate any pointers so I can carry on playing!
Thanks
Code:
/*
Working Code for remote control
red
yellow
green LEDs
with different functions
*/
#include <IRremote.h>
int IRpin = 11; // pin for the IR sensor
int LEDYellow = 13; // Yellow LED pin
int LEDRed = 9; // Red LED pin
int LEDGreen = 5; //Green LED pin
IRrecv irrecv(IRpin);
decode_results results;
boolean LEDon = true; // initializing LEDon as true
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(LEDYellow, OUTPUT); //Pinmode set
pinMode(LEDRed, OUTPUT);
pinMode(LEDGreen, OUTPUT);
}
void loop()
{
if (irrecv.decode(&results))
{
irrecv.resume(); // Receive the next value
}
if (results.value == 546983) // remote control code from serial monitor
{
if (LEDon == true) // is LEDon equal to true?
{
LEDon = false;
digitalWrite(LEDYellow, HIGH);
delay(100); // keeps the transistion smooth
}
else
{
LEDon = true;
digitalWrite(LEDYellow, LOW);
delay(100);
}
}
if (results.value == 571463)
{
if (LEDon == true) // is LEDon equal to true?
{
LEDon = false;
digitalWrite(LEDRed, HIGH);
delay(100); // keeps the transistion smooth
}
else
{
LEDon = true;
digitalWrite(LEDRed, LOW);
delay(100);
}
}
if (results.value == 538823)
{
if (LEDon == true) // is LEDon equal to true?
{
LEDon = false;
digitalWrite(LEDGreen, HIGH);
delay(100); // keeps the transistion smooth
}
else
{
LEDon = true;
digitalWrite(LEDGreen, LOW);
delay(100);
}
}
}