Skip to content

Instantly share code, notes, and snippets.

@ajesler
Last active November 13, 2016 20:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajesler/16b2b5073d4a6fe0bada to your computer and use it in GitHub Desktop.
Save ajesler/16b2b5073d4a6fe0bada to your computer and use it in GitHub Desktop.
Arduino sketch for a remote controllable LED lamp.
// IRLib from https://github.com/cyborg5/IRLib
#include <IRLib.h>
// RGBEffects from https://github.com/ajesler/Arduino-RGBEffects
#include <RGBEffects.h>
// if isPaused is true, update will stop being called until the lamp is unpaused.
int isPaused = 0;
// the time between effect updates.
int effect_delay = 2100;
#define EFFECT_DELAY_STEP 400
#define EFFECT_DELAY_MIN 100
#define PAUSE_DELAY 300
/* START LED EFFECTS CONFIGURATION */
#define RED_PIN 5
#define GREEN_PIN 6
#define BLUE_PIN 9
RGBEffects rgbEffects( RED_PIN, GREEN_PIN, BLUE_PIN );
/* END LED EFFECTS CONFIGURATION */
/* START IR CONFIGURATION*/
#define IR_RECV_PIN 4
IRrecv irReceiver(IR_RECV_PIN);
IRdecode irDecoder;
// Hex codes of remote buttons
#define BTN_PLAY_PAUSE 0xFF22DD
#define BTN_PLUS 0xFF906F
#define BTN_MINUS 0xFFA857
#define BTN_REWIND 0xFF02FD
#define BTN_FAST_FORWARD 0xFFC23D
#define BTN_0 0xFF6897
#define BTN_1 0xFF30CF
#define BTN_2 0xFF18E7
#define BTN_3 0xFF7A85
#define BTN_4 0xFF10EF
#define BTN_5 0xFF38C7
#define BTN_6 0xFF5AA5
#define BTN_7 0xFF42BD
#define BTN_8 0xFF4AB5
#define BTN_9 0xFF52AD
#define BTN_MODE 0xFF629D
/* END IR CONFIGURATION*/
void increaseEffectDelay(){
effect_delay += EFFECT_DELAY_STEP;
}
void decreaseEffectDelay(){
if(effect_delay - EFFECT_DELAY_STEP >= EFFECT_DELAY_MIN){
effect_delay -= EFFECT_DELAY_STEP;
}
}
void processIRCommand(int command){
switch(command){
case BTN_PLAY_PAUSE:
isPaused = !isPaused;
break;
case BTN_0:
rgbEffects.setEffect(EFFECT_RAINBOW);
break;
case BTN_1:
rgbEffects.setEffect(EFFECT_FADE);
break;
case BTN_2:
rgbEffects.setEffect(EFFECT_CUBE);
break;
case BTN_3:
rgbEffects.setEffect(EFFECT_SOLID_RED);
break;
case BTN_4:
rgbEffects.setEffect(EFFECT_SOLID_GREEN);
break;
case BTN_5:
rgbEffects.setEffect(EFFECT_SOLID_BLUE);
break;
case BTN_6:
rgbEffects.setEffect(EFFECT_SOLID_YELLOW);
break;
case BTN_7:
rgbEffects.setEffect(EFFECT_SOLID_PURPLE);
break;
case BTN_8:
rgbEffects.setEffect(EFFECT_SOLID_VIOLET);
break;
case BTN_9:
rgbEffects.setEffect(EFFECT_SOLID_WHITE);
break;
case BTN_PLUS:
increaseEffectDelay();
break;
case BTN_MINUS:
decreaseEffectDelay();
break;
case BTN_MODE:
rgbEffects.nextEffect();
break;
}
}
void setup(){
irReceiver.No_Output(); //Turn off any unused IR LED output circuit
irReceiver.enableIRIn(); // Start the receiver
randomSeed(analogRead(0));
rgbEffects.setEffect(EFFECT_RAINBOW);
}
void loop(){
// handle any received IR commands
if (irReceiver.GetResults(&irDecoder)) {
irDecoder.decode();
if(irDecoder.decode_type==NEC){
processIRCommand(irDecoder.value);
}
// get ready to receive the next command
irReceiver.resume();
}
if(!isPaused){
rgbEffects.update();
delay(effect_delay);
} else {
delay(PAUSE_DELAY);
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment