Add support for new IR codes.
This commit is contained in:
parent
5d88eb1173
commit
f3a8aa8d59
125
project-lamp.ino
125
project-lamp.ino
|
@ -3,9 +3,11 @@
|
||||||
#include <IRremote.h>
|
#include <IRremote.h>
|
||||||
|
|
||||||
#define NUM_LEDS 1
|
#define NUM_LEDS 1
|
||||||
#define DATA_PIN 4
|
#define DATA_PIN 3
|
||||||
|
|
||||||
#define IR_RECEIVE_PIN 2
|
#define IR_RECEIVE_PIN 2
|
||||||
|
#undef ENABLE_LED_FEEDBACK
|
||||||
|
#define ENABLE_LED_FEEDBACK 0
|
||||||
|
|
||||||
CRGBW COL_RED (255, 0, 0, 0);
|
CRGBW COL_RED (255, 0, 0, 0);
|
||||||
CRGBW COL_GREEN ( 0,255, 0, 0);
|
CRGBW COL_GREEN ( 0,255, 0, 0);
|
||||||
|
@ -33,19 +35,22 @@ CRGBW desaturate(CRGBW col)
|
||||||
struct ColourCode
|
struct ColourCode
|
||||||
{
|
{
|
||||||
uint32_t code;
|
uint32_t code;
|
||||||
|
uint32_t altCode;
|
||||||
CRGBW colour;
|
CRGBW colour;
|
||||||
CRGBW altColour;
|
CRGBW altColour;
|
||||||
|
|
||||||
ColourCode(uint32_t c, CRGBW col)
|
ColourCode(uint32_t c, uint32_t c2,CRGBW col)
|
||||||
{
|
{
|
||||||
code = c;
|
code = c;
|
||||||
|
altCode = c2;
|
||||||
colour = col;
|
colour = col;
|
||||||
altColour = desaturate(col);
|
altColour = desaturate(col);
|
||||||
}
|
}
|
||||||
|
|
||||||
ColourCode(uint32_t c, CRGBW colA, CRGBW colB)
|
ColourCode(uint32_t c, uint32_t c2, CRGBW colA, CRGBW colB)
|
||||||
{
|
{
|
||||||
code = c;
|
code = c;
|
||||||
|
altCode = c2;
|
||||||
colour = colA;
|
colour = colA;
|
||||||
altColour = colB;
|
altColour = colB;
|
||||||
}
|
}
|
||||||
|
@ -53,45 +58,65 @@ struct ColourCode
|
||||||
|
|
||||||
const ColourCode colourCodes[] =
|
const ColourCode colourCodes[] =
|
||||||
{
|
{
|
||||||
{0x97483BFB, COL_RED},
|
{0xE619FF00, 0xFB04EF00, COL_RED},
|
||||||
{0x86B0E697, COL_GREEN},
|
{0xE41BFF00, 0xFA05EF00, COL_GREEN},
|
||||||
{0x9EF4941F, COL_BLUE},
|
{0xEE11FF00, 0xF906EF00, COL_BLUE},
|
||||||
{0xA3C8EDDB, COL_SUM, COL_WHITE},
|
{0xEA15FF00, 0xF807EF00, COL_SUM, COL_WHITE},
|
||||||
{0x5BE75E7F, COL_AMBER},
|
{0xE817FF00, 0xF708EF00, COL_AMBER},
|
||||||
{0xF377C5B7, COL_LIME},
|
{0xED12FF00, 0xF609EF00, COL_LIME},
|
||||||
{0xC101E57B, COL_AZURE},
|
{0xE916FF00, 0xF50AEF00, COL_AZURE},
|
||||||
{0xD7E84B1B, COL_ORANGE},
|
{0xBF40FF00, 0xF30CEF00, COL_ORANGE},
|
||||||
{0xEE4ECCFB, COL_CYAN},
|
{0xB34CFF00, 0xF20DEF00, COL_CYAN},
|
||||||
{0x51E43D1B, COL_UV},
|
{0xFB04FF00, 0xF10EEF00, COL_UV},
|
||||||
{0x2A89195F, COL_PEACHY},
|
{0xF50AFF00, 0xEF10EF00, COL_PEACHY},
|
||||||
{0xF63C8657, COL_SPRING},
|
{0xE11EFF00, 0xEE11EF00, COL_SPRING},
|
||||||
{0x44C407DB, COL_MAGENTA},
|
{0xF10EFF00, 0xED12EF00, COL_MAGENTA},
|
||||||
{0x488F3CBB, COL_YELLOW},
|
{0xE31CFF00, 0xEB14EF00, COL_YELLOW},
|
||||||
{0x13549BDF, COL_VIOLET},
|
{0xEB14FF00, 0xEA15EF00, COL_VIOLET},
|
||||||
{0x35A9425F, COL_ROSE}
|
{0xF00FFF00, 0xE916EF00, COL_ROSE}
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint32_t CODE_BRIGHTER = 0xE5CFBD7F;
|
const uint32_t CODE_BRIGHTER = 0xFF00EF00;
|
||||||
const uint32_t CODE_DIMMER = 0xA23C94BF;
|
const uint32_t CODE_DIMMER = 0xFE01EF00;
|
||||||
const uint32_t CODE_OFF = 0xE721C0DB;
|
const uint32_t CODE_OFF = 0xFD02EF00;
|
||||||
const uint32_t CODE_ON = 0xF0C41643;
|
const uint32_t CODE_ON = 0xFC03EF00;
|
||||||
|
const uint32_t CODE_FLASH = 0xF40BEF00;
|
||||||
|
const uint32_t CODE_STROBE = 0xF00FEF00;
|
||||||
|
const uint32_t CODE_FADE = 0xEC13EF00;
|
||||||
|
const uint32_t CODE_SMOOTH = 0xE817EF00;
|
||||||
|
|
||||||
const int NUM_COLOURCODES = sizeof(colourCodes) / sizeof(ColourCode);
|
const int NUM_COLOURCODES = sizeof(colourCodes) / sizeof(ColourCode);
|
||||||
|
|
||||||
CRGBW leds[NUM_LEDS];
|
CRGBW leds[NUM_LEDS];
|
||||||
CRGB *ledsRGB = (CRGB *) &leds[0];
|
CRGB *ledsRGB = (CRGB *) &leds[0];
|
||||||
|
|
||||||
IRrecv irrecv(IR_RECEIVE_PIN);
|
//IRrecv irrecv(IR_RECEIVE_PIN);/
|
||||||
|
|
||||||
uint8_t brightness = 128;
|
uint8_t brightness = 128;
|
||||||
uint32_t lastCode = 0;
|
uint32_t lastCode = 0;
|
||||||
|
|
||||||
decode_results results;
|
decode_results results;
|
||||||
|
|
||||||
|
void colorFill(CRGBW c){
|
||||||
|
for(int i = 0; i < NUM_LEDS; i++){
|
||||||
|
leds[i] = c;
|
||||||
|
FastLED.show();
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void colorFill(CRGB c){
|
||||||
|
for(int i = 0; i < NUM_LEDS; i++){
|
||||||
|
leds[i] = c;
|
||||||
|
FastLED.show();
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(ledsRGB, getRGBWsize(NUM_LEDS));
|
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(ledsRGB, getRGBWsize(NUM_LEDS));
|
||||||
FastLED.setBrightness(128);
|
colorFill(COL_SUM);
|
||||||
|
FastLED.setBrightness(255);
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
|
|
||||||
|
@ -109,80 +134,84 @@ void setup() {
|
||||||
// In case the interrupt driver crashes on setup, give a clue
|
// In case the interrupt driver crashes on setup, give a clue
|
||||||
// to the user what's going on.
|
// to the user what's going on.
|
||||||
Serial.println("Enabling IRin");
|
Serial.println("Enabling IRin");
|
||||||
irrecv.enableIRIn(); // Start the receiver
|
// irrecv.enableIRIn(); // Start the receiver/
|
||||||
|
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
|
||||||
|
|
||||||
Serial.print(F("Ready to receive IR signals at pin "));
|
Serial.print(F("Ready to receive IR signals at pin "));
|
||||||
Serial.println(IR_RECEIVE_PIN);
|
Serial.println(IR_RECEIVE_PIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void colorFill(CRGBW c){
|
|
||||||
for(int i = 0; i < NUM_LEDS; i++){
|
|
||||||
leds[i] = c;
|
|
||||||
FastLED.show();
|
|
||||||
delay(50);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void colorFill(CRGB c){
|
|
||||||
for(int i = 0; i < NUM_LEDS; i++){
|
|
||||||
leds[i] = c;
|
|
||||||
FastLED.show();
|
|
||||||
delay(50);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void interpretColourCode(uint32_t code)
|
void interpretColourCode(uint32_t code)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < NUM_COLOURCODES; i++)
|
for (int i = 0; i < NUM_COLOURCODES; i++)
|
||||||
{
|
{
|
||||||
ColourCode col = colourCodes[i];
|
ColourCode col = colourCodes[i];
|
||||||
if (col.code == code)
|
if (col.code == code || col.altCode == code)
|
||||||
{
|
{
|
||||||
if (code == lastCode)
|
if (code == lastCode)
|
||||||
{
|
{
|
||||||
|
Serial.println(F("Colour code OK - Secondary"));
|
||||||
colorFill(col.altColour);
|
colorFill(col.altColour);
|
||||||
lastCode = 0;
|
lastCode = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Serial.println(F("Colour code OK - Primary"));
|
||||||
colorFill(col.colour);
|
colorFill(col.colour);
|
||||||
lastCode = code;
|
lastCode = code;
|
||||||
}
|
}
|
||||||
break;
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Serial.print(code, HEX);
|
||||||
|
// Serial.print(F(" != "));
|
||||||
|
// Serial.println(col.code, HEX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Serial.println(F("CODE?!?!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if (irrecv.decode(&results))
|
if (IrReceiver.decode())
|
||||||
{
|
{
|
||||||
Serial.println(results.value, HEX);
|
uint32_t data = IrReceiver.decodedIRData.decodedRawData;
|
||||||
irrecv.resume(); // Receive the next value
|
Serial.println(data, HEX);
|
||||||
switch(results.value)
|
IrReceiver.resume(); // Receive the next value
|
||||||
|
switch(data)
|
||||||
{
|
{
|
||||||
case CODE_BRIGHTER:
|
case CODE_BRIGHTER:
|
||||||
brightness += 32;
|
brightness += 32;
|
||||||
FastLED.setBrightness(brightness);
|
FastLED.setBrightness(brightness);
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
|
Serial.println(F("Brighter"));
|
||||||
break;
|
break;
|
||||||
case CODE_DIMMER:
|
case CODE_DIMMER:
|
||||||
brightness -= 32;
|
brightness -= 32;
|
||||||
FastLED.setBrightness(brightness);
|
FastLED.setBrightness(brightness);
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
|
Serial.println(F("Dimmer"));
|
||||||
break;
|
break;
|
||||||
case CODE_OFF:
|
case CODE_OFF:
|
||||||
FastLED.setBrightness(0);
|
FastLED.setBrightness(0);
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
|
Serial.println(F("Off"));
|
||||||
break;
|
break;
|
||||||
case CODE_ON:
|
case CODE_ON:
|
||||||
FastLED.setBrightness(brightness);
|
FastLED.setBrightness(brightness);
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
|
Serial.println(F("On"));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
interpretColourCode(results.value);
|
interpretColourCode(data);
|
||||||
|
Serial.println(F("Set colour"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (brightness <= 0)
|
||||||
|
brightness = 255;
|
||||||
}
|
}
|
||||||
delay(100);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue