Created
April 22, 2016 12:48
-
-
Save RIscRIpt/86b857f32eb8af4508b6a80d31d6cbef to your computer and use it in GitHub Desktop.
Arduino // tv_remote + relay
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
//https://geektimes.ru/post/255488/ | |
#include <IRremote.h> | |
#define IR_KEY_POWER 0x807F08F7 | |
#define IR_KEY_MENU 0x807FA857 | |
#define IR_KEY_VOLUME_MORE 0x807F708F | |
#define IR_KEY_VOLUME_LESS 0x807FF00F | |
#define IR_KEY_PROGRAM_NEXT 0x807F30CF | |
#define IR_KEY_PROGRAM_PREV 0x807FB04F | |
#define IR_KEY_UP 0x807F9867 | |
#define IR_KEY_DOWN 0x807F58A7 | |
#define IR_KEY_LEFT 0x807FD827 | |
#define IR_KEY_RIGHT 0x807F38C7 | |
#define IR_KEY_AV 0x807F48B7 | |
#define IR_KEY_ENTER 0x807FB847 | |
#define IR_KEY_EXIT 0x807F6897 | |
IRsend irsend; | |
void setup() { | |
pinMode(2, OUTPUT); | |
pinMode(4, OUTPUT); | |
pinMode(5, OUTPUT); | |
pinMode(6, OUTPUT); | |
pinMode(7, OUTPUT); | |
pinMode(8, OUTPUT); | |
pinMode(9, OUTPUT); | |
pinMode(10, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
while(Serial.available() < 1) | |
; | |
char device = Serial.read(); | |
switch(device) { | |
case 'r': //Relay | |
relay_toggle(); | |
break; | |
case 'c': //Controller | |
controller_action(); | |
break; | |
} | |
} | |
void relay_toggle() { | |
while(Serial.available() < 2) | |
; | |
char pin = Serial.read() - '0'; | |
char action = Serial.read(); | |
//Verify data | |
if(pin >= 0 && pin <= 10 && (action == '+' || action == '-')) { | |
digitalWrite(pin, action == '+' ? HIGH : LOW); | |
/* if(action == '+') | |
* HIGH | |
* else | |
* LOW | |
*/ | |
} | |
} | |
void controller_action() { | |
while(Serial.available() < 1) | |
; | |
char button = Serial.read(); | |
switch(button) { | |
case 'P': | |
irsend.sendNEC(IR_KEY_POWER, 32); | |
break; | |
case 'M': | |
irsend.sendNEC(IR_KEY_MENU, 32); | |
break; | |
case '+': | |
irsend.sendNEC(IR_KEY_VOLUME_MORE, 32); | |
break; | |
case '-': | |
irsend.sendNEC(IR_KEY_VOLUME_LESS, 32); | |
break; | |
case 'F': | |
irsend.sendNEC(IR_KEY_PROGRAM_NEXT, 32); | |
break; | |
case 'B': | |
irsend.sendNEC(IR_KEY_PROGRAM_PREV, 32); | |
break; | |
case 'U': | |
irsend.sendNEC(IR_KEY_UP, 32); | |
break; | |
case 'D': | |
irsend.sendNEC(IR_KEY_DOWN, 32); | |
break; | |
case 'L': | |
irsend.sendNEC(IR_KEY_LEFT, 32); | |
break; | |
case 'R': | |
irsend.sendNEC(IR_KEY_RIGHT, 32); | |
break; | |
case 'A': | |
irsend.sendNEC(IR_KEY_AV, 32); | |
break; | |
case 'E': | |
irsend.sendNEC(IR_KEY_ENTER, 32); | |
break; | |
case 'X': | |
irsend.sendNEC(IR_KEY_EXIT, 32); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment