Created
November 15, 2013 23:15
-
-
Save biomood/7493332 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> | |
#include "Timer.h" | |
#define CMD_CONST_COLOUR (1 << 4) | |
#define CMD_FLASH (1 << 5) | |
#define CMD_ALT (1 << 6) | |
#define CMD_OFF 0 | |
#define COL_RED_K (1 << 4) | |
#define COL_GREEN_K (1 << 5) | |
#define COL_BLUE_K (3 << 4) | |
#define COL_WHITE_K (1 << 6) | |
#define COL_ORANGE_K (5 << 4) | |
#define COL_LGREEN_K (6 << 4) | |
#define COL_LBLUE_K (7 << 4) | |
#define COL_MORANGE_K (1 << 7) | |
#define COL_VLBLUE_K (9 << 4) | |
#define COL_PURPLE_K (10 << 4) | |
#define COL_LORANGE_K (11 << 4) | |
#define COL_MLBLUE_K (12 << 4) | |
#define COL_LPINK_K (13 << 4) | |
#define COL_YELLOW_K (14 << 4) | |
#define COL_MBLUE_K (15 << 4) | |
#define COL_PINK_K 0 | |
#define COL_RED_C 0xF720DF | |
#define COL_GREEN_C 0xF7A05F | |
#define COL_BLUE_C 0xF7609F | |
#define COL_WHITE_C 0xF7E01F | |
#define COL_ORANGE_C 0xF710EF | |
#define COL_LGREEN_C 0xF7906F | |
#define COL_LBLUE_C 0xF750AF | |
#define COL_MORANGE_C 0xF730CF | |
#define COL_VLBLUE_C 0xF7B04F | |
#define COL_PURPLE_C 0xF7708F | |
#define COL_LORANGE_C 0xF708F7 | |
#define COL_MLBLUE_C 0xF78877 | |
#define COL_LPINK_C 0xF748B7 | |
#define COL_YELLOW_C 0xF728D7 | |
#define COL_MBLUE_C 0xF7A857 | |
#define COL_PINK_C 0xF76897 | |
#define OFF 0xF740BF | |
const int PIN_2 = 2; | |
boolean flash = true; | |
byte last_cmd, selected_col, alt_c, alt_c2; | |
int ID_timer; | |
IRsend irsend; | |
Timer t; | |
void sendIR(byte val) { | |
switch (val) { | |
case COL_RED_K: | |
irsend.sendNEC(COL_RED_C, 32); | |
break; | |
case COL_GREEN_K: | |
irsend.sendNEC(COL_GREEN_C, 32); | |
break; | |
case COL_BLUE_K: | |
irsend.sendNEC(COL_BLUE_C, 32); | |
break; | |
case COL_WHITE_K: | |
irsend.sendNEC(COL_WHITE_C, 32); | |
break; | |
case COL_ORANGE_K: | |
irsend.sendNEC(COL_ORANGE_C, 32); | |
break; | |
case COL_LGREEN_K: | |
irsend.sendNEC(COL_LGREEN_C, 32); | |
break; | |
case COL_LBLUE_K: | |
irsend.sendNEC(COL_LBLUE_C, 32); | |
break; | |
case COL_MORANGE_K: | |
irsend.sendNEC(COL_MORANGE_C, 32); | |
break; | |
case COL_VLBLUE_K: | |
irsend.sendNEC(COL_VLBLUE_C, 32); | |
break; | |
case COL_PURPLE_K: | |
irsend.sendNEC(COL_PURPLE_C, 32); | |
break; | |
case COL_LORANGE_K: | |
irsend.sendNEC(COL_LORANGE_C, 32); | |
break; | |
case COL_MLBLUE_K: | |
irsend.sendNEC(COL_MLBLUE_C, 32); | |
break; | |
case COL_LPINK_K: | |
irsend.sendNEC(COL_LPINK_C, 32); | |
break; | |
case COL_YELLOW_K: | |
irsend.sendNEC(COL_YELLOW_C, 32); | |
break; | |
case COL_MBLUE_K: | |
irsend.sendNEC(COL_MBLUE_C, 32); | |
break; | |
case COL_PINK_K: | |
irsend.sendNEC(COL_PINK_C, 32); | |
break; | |
} | |
} | |
void flashCallback() { | |
if (flash) { | |
sendIR(selected_col); | |
} | |
else { | |
irsend.sendNEC(OFF, 32); | |
} | |
flash =!flash; | |
} | |
void altCallback() { | |
if (flash){ | |
sendIR(alt_c); | |
} | |
else { | |
sendIR(alt_c2); | |
} | |
flash=!flash; | |
} | |
void setup() { | |
Serial.begin(9600); | |
// IR LED | |
pinMode(PIN_2, OUTPUT); | |
digitalWrite(PIN_2, LOW); | |
} | |
void loop() { | |
if (Serial.available()) { | |
byte cmd = Serial.read(); | |
if ((last_cmd == CMD_FLASH) || (last_cmd == CMD_ALT)) { | |
t.stop(ID_timer); | |
} | |
switch (cmd) { | |
case CMD_CONST_COLOUR: { | |
while (Serial.available() == 0); | |
byte v = Serial.read(); | |
sendIR(v); | |
break; | |
} | |
case CMD_FLASH: { | |
while (Serial.available() == 0); | |
selected_col = Serial.read(); | |
ID_timer = t.every(750, flashCallback); | |
break; | |
} | |
case CMD_ALT: { | |
while (Serial.available() == 0); | |
alt_c = Serial.read(); | |
while (Serial.available() == 0); | |
alt_c2 = Serial.read(); | |
ID_timer = t.every(750, altCallback); | |
break; | |
} | |
case CMD_OFF: { | |
irsend.sendNEC(OFF, 32); | |
break; | |
} | |
} | |
last_cmd = cmd; | |
} | |
if ((last_cmd == CMD_FLASH) || (last_cmd == CMD_ALT)) { | |
t.update(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment