123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include <IRremote.h>
- const int led = LED_BUILTIN; // On board LED, Pin 13
- const int RECV_PIN = 7; // IR Receiver
- String input = "";
- bool done = false;
- IRsend sendr; // Make Send Object, DANGER a fixed pin number is always used! (3)
- //IRrecv recvr(RECV_PIN); // Make Recever Object
- decode_results results; // Make Results Object to store received codes
- void setup() {
- // Initalize on board LED
- pinMode(led, OUTPUT);
- digitalWrite(led, LOW);
-
- // Initalize input routine
- input.reserve(60); // Max input of chars, to merge into string
- done = false;
- // Initalize IR connections
- //recvr.enableIRIn();
- //recvr.blink13(false); // Disabled Pin 13 blinking on IR signal received
-
- // Initalize Output routine
- Serial.begin(9600); // Serial COM's Port
- while(!Serial) { delay(10); } // Wait for conection
- Serial.println("Serial Connected!");
- digitalWrite(led, LOW);
- }
- void sendCode(long code, int bit_len, bool repeat) {
- // If repeat the code then repeat it 3 times
- if(repeat) {
- for(int x = 0; x <= 3; x++) {
- sendr.sendNEC(code, bit_len);
- delay(40);
- }
- } else {
- // Else send the code then repeat a blank 2 times
- sendr.sendNEC(code, bit_len);
- delay(40);
- for(int x = 0; x <= 2; x++) {
- sendr.sendNEC(0xFFFFFFFF, 32);
- delay(40);
- }
- }
- }
- void action(String act){
- // Given String execute action
- if(act == "tv p"){
- sendCode(0x57E3E817, 32, true);
- /*for(int x = 0; x <= 3; x++) {
- sendr.sendNEC(0x57E3E817, 32);
- delay(40);
- }*/
- Serial.println("tv power");
- }/* else if(act == "m p"){
- sendCode(0x807F02FD, 32, false);
- Serial.println("movie power");
- }*/
- }
- void loop() {
- // Are we sending/receiving data?
- if(Serial.available() > 0) {
- char in = (char)Serial.read();
- if (in == '\n') {
- done = true;
- } else if (in == '\n') {
- done = true;
- } else {
- input += in;
- }
- }
- if(done){
- action(input); // Execute command / handle command
- input = "";
- done = false;
- }
- }
|