Created
September 20, 2016 00:42
-
-
Save dbarrerap/1036f6b9034b49f61e805b62957cf464 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <IRremote.h> | |
#define foreachled for (int i = 0; i < sizeof(rgbLED); i++) | |
// Codes for Remote Control | |
#define RivieraRED 0x2FD52AD | |
#define RivieraGREEN 0x2FDD22D | |
#define RivieraBLUE 0x2FDB24D | |
#define RivieraPOWER 0x2FD48B7 | |
#define RivieraUP 0x2FD41BE | |
#define RivieraDOWN 0x2FDC13E | |
// Common Cathode RGB LED :: 255 (HIGH) off, 0 (LOW) on | |
// if using Common Anode, invert values | |
byte rgbLevel[] = {255, 255, 255}; | |
byte rgbLED[] = {10, 9, 6}; | |
bool ledOn = false; | |
// Will store which color will be modified | |
byte rgbControl; | |
byte RECV_PIN = 5; | |
IRrecv irrecv(RECV_PIN); | |
decode_results results; | |
void setup() { | |
Serial.begin(9600); | |
irrecv.enableIRIn(); | |
// Start with LED off | |
foreachled { | |
analogWrite(rgbLED[i], rgbLevel[i]); | |
} | |
} | |
void loop() { | |
if (irrecv.decode(&results)) { | |
Serial.print(results.value, HEX); | |
Serial.print(" "); | |
switch (results.value) { | |
case RivieraPOWER: | |
Serial.println(F("On/Off")); | |
// Will check for ledOn and turn on or off accordingly | |
foreachled { | |
rgbLevel[i] = (ledOn ? 255 : 0); | |
} | |
foreachled { | |
analogWrite(rgbLED[i], rgbLevel[i]); | |
} | |
ledOn = !ledOn; | |
break; | |
case RivieraRED: | |
Serial.println(F("Controlling R")); | |
rgbControl = 0; | |
break; | |
case RivieraGREEN: | |
Serial.println(F("Controlling G")); | |
rgbControl = 1; | |
break; | |
case RivieraBLUE: | |
Serial.println(F("Controlling B")); | |
rgbControl = 2; | |
break; | |
case RivieraUP: | |
case RivieraDOWN: | |
Serial.println(F("Increment/Decrement")); | |
changeValue(); | |
break; | |
default: | |
Serial.println(F("Code not recognized")); | |
} | |
irrecv.resume(); | |
} | |
delay(250); | |
} | |
void changeValue() { | |
switch (results.value) { | |
case RivieraUP: | |
rgbLevel[rgbControl] = (rgbLevel[rgbControl] > 0 ? rgbLevel[rgbControl] - 5 : 0); | |
break; | |
case RivieraDOWN: | |
rgbLevel[rgbControl] = (rgbLevel[rgbControl] < 255 ? rgbLevel[rgbControl] + 5 : 255); | |
break; | |
} | |
foreachled { | |
analogWrite(rgbLED[i], rgbLevel[i]); | |
} | |
if (!ledOn) ledOn = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment