Here’s the sketch from Git hub
#include <IRremote.h> // Include the IRremote library
/* Setup constants for SparkFun’s IR Remote: */
#define NUM_BUTTONS 9 // The remote has 9 buttons
/* Define the IR remote button codes. We’re only using the
least signinficant two bytes of these codes. Each one
should actually have 0x10EF in front of it. Find these codes
by running the IRrecvDump example sketch included with
the IRremote library.*/
const uint16_t BUTTON_POWER = 0xD827; // i.e. 0x10EFD827
const uint16_t BUTTON_A = 0xF807;
const uint16_t BUTTON_B = 0x7887;
const uint16_t BUTTON_C = 0x58A7;
const uint16_t BUTTON_UP = 0xA05F;
const uint16_t BUTTON_DOWN = 0x00FF;
const uint16_t BUTTON_LEFT = 0x10EF;
const uint16_t BUTTON_RIGHT = 0x807F;
const uint16_t BUTTON_CIRCLE = 0x20DF;
/* Connect the output of the IR receiver diode to pin 11. */
int RECV_PIN = 11;
/* Initialize the irrecv part of the IRremote library */
11
decode_results results; // This will store our IR received codes
uint16_t lastCode = 0; // This keeps track of the last code RX’d
/* Setup RGB LED pins: */
enum ledOrder // Make an enum to add some clarity in the code
{
RED, // 0
GREEN, // 1
BLUE // 2
};
const int rgbPins[3] = {5, 9, 6}; // Red, green, blue pins respectively
byte rgbValues[3] = {55, 23, 200}; // This keeps track of channel brightness
byte activeChannel = RED; // Start with RED as the active channel
boolean ledEnable = 1; // Start with the LED on.
void setup()
{
Serial.begin(9600); // Use serial to debug.
irrecv.enableIRIn(); // Start the receiver
/* Set up the RGB LED pins: */
for (int i=0; i<3; i++)
{
pinMode(rgbPins*, OUTPUT);*
analogWrite(rgbPins, rgbValues);
}
}
// loop() constantly checks for any received IR codes. At the
// end it updates the RGB LED.
void loop()
{
if (irrecv.decode(&results))
{
/* read the RX’d IR into a 16-bit variable: */
uint16_t resultCode = (results.value & 0xFFFF);
/* The remote will continue to spit out 0xFFFFFFFF if a
button is held down. If we get 0xFFFFFFF, let’s just
assume the previously pressed button is being held down */
if (resultCode == 0xFFFF)
resultCode = lastCode;
else
lastCode = resultCode;
// This switch statement checks the received IR code against
// all of the known codes. Each button press produces a
// serial output, and has an effect on the LED output.
switch (resultCode)
{
case BUTTON_POWER:
Serial.println(“Power”);
if (ledEnable) ledEnable = 0;
else ledEnable = 1; // Flip ledEnable
break;
case BUTTON_A:
Serial.println(“A”);
activeChannel = RED;
break;
case BUTTON_B:
Serial.println(“B”);
activeChannel = GREEN;
break;
case BUTTON_C:
Serial.println(“C”);
activeChannel = BLUE;
break;
case BUTTON_UP:
Serial.println(“Up”);
rgbValues[activeChannel]++; // Increment brightness
break;
case BUTTON_DOWN:
Serial.println(“Down”);
rgbValues[activeChannel]–; // Decrement brightness
break;
case BUTTON_LEFT:
Serial.println(“Left”);
rgbValues[activeChannel] = 0; // Min brightness (off)
break;
case BUTTON_RIGHT:
Serial.println(“Right”);
rgbValues[activeChannel] = 255; // Max brightness
break;
case BUTTON_CIRCLE:
Serial.println(“Circle”);
rgbValues[activeChannel] = 127; // Medium brightness
break;
default:
Serial.print(“Unrecognized code received: 0x”);
Serial.println(results.value, HEX);
break;
}
irrecv.resume(); // Receive the next value
}
// Every time through the loop, update the RGB LEDs:
if (ledEnable)
{
for (int i=0; i<3; i++)
{
analogWrite(rgbPins, rgbValues);
}
}
else
{
for (int i=0; i<3; i++)
{
analogWrite(rgbPins, 0);
}
}
}