//Tutorial 68:RGB with Remote
#include <IRremote.h> //Install or add the library
int IRpin=8; //Data pin is connected to arduino pin 9
IRrecv IR(IRpin); //Create an object, IR is an object
decode_results cmd; //cmd Variable to store data from remote
String myCom; //Variable for store HEX values
int red=9;
int green=10;
int blue=11;
void setup()
{
Serial.begin(9600); //Start serial monitor
IR.enableIRIn(); //Enable IR
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}
void loop()
{
while (IR.decode(&cmd)==0) //Waiting for input
{
//Wait
}
Serial.println(cmd.value,HEX); //Print values from remote
delay(500); //Delay
IR.resume(); //Ready to receive new data from remote
if (cmd.value==0xFF45BA) //If condition is true then enter in the loop
{
myCom="Power"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF16E9)//If condition is true then enter in the loop
{
myCom="Zero"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF0CF3) //If condition is true then enter in the loop
{
myCom="1"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF18E7) //If condition is true then enter in the loop
{
myCom="2"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF5EA1) //If condition is true then enter in the loop
{
myCom="3"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF08F7) //If condition is true then enter in the loop
{
myCom="4"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF1CE3) //If condition is true then enter in the loop
{
myCom="5"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF5AA5) //If condition is true then enter in the loop
{
myCom="6"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF42BD) //If condition is true then enter in the loop
{
myCom="7"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF52AD) //If condition is true then enter in the loop
{
myCom="8"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF4AB5) //If condition is true then enter in the loop
{
myCom="9"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF47B8) //If condition is true then enter in the loop
{
myCom="Menu"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF15EA) //If condition is true then enter in the loop
{
myCom="Play"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF19E6) //If condition is true then enter in the loop
{
myCom="Down"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if (cmd.value==0xFF40BF) //If condition is true then enter in the loop
{
myCom="Up"; //Store string in the "myCom"
Serial.println(myCom); //print the value of myCom
}
if(myCom=="Power")
{
digitalWrite(red, HIGH);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
}
if(myCom=="Zero")
{
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
if(myCom=="1")
{
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
}
if(myCom=="2")
{
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
digitalWrite(blue, LOW);
}
if(myCom=="3")
{
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, HIGH);
}
if(myCom=="4")
{
analogWrite(red, 0);
analogWrite(green, 255);
analogWrite(blue, 255);
}
if(myCom=="5")
{
analogWrite(red, 255);
analogWrite(green, 0);
analogWrite(blue, 255);
}
if(myCom=="6")
{
analogWrite(red, 255);
analogWrite(green, 255);
analogWrite(blue, 0);
}
if(myCom=="")
{
analogWrite(red, 255);
analogWrite(green, 0);
analogWrite(blue, 255);
}
}