Created
July 5, 2012 17:00
-
-
Save dgomes/3054880 to your computer and use it in GitHub Desktop.
Remote IR and RF Control for Sony TV and Chacon Ref:54656
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
/* | |
* iRemotuino - Remote IR and RF Control for Sony TV and Chacon Ref:54656 | |
* Diogo Gomes <diogogomes@gmail.com> | |
* Copyright 2012 | |
*/ | |
#include <IRremote.h> //http://github.com/shirriff/Arduino-IRremot | |
#include <RemoteTransmitter.h> //https://bitbucket.org/fuzzillogic/433mhzforarduino | |
IRsend irsend; | |
#define IRLED_PIN 3 | |
#define RFTRANSMITTER_PIN 9 | |
#define RF_PERIOD 493 //usecs (as detected for Chacon Ref:54656 using a 434mhz receiver and fuzzillogic example code) | |
#define SONY 'S' | |
#define RC5 'Z' //used by ZonBox (Thomson model at least) | |
#define RF 'R' | |
void setup() | |
{ | |
pinMode(IRLED_PIN, OUTPUT); | |
pinMode(RFTRANSMITTER_PIN, OUTPUT); | |
Serial.begin(9600); | |
} | |
unsigned long readCode() { | |
// Read 8 hex characters | |
if (Serial.available() < 8) return 0; | |
unsigned long code = 0; | |
for (int i = 0; i < 8; i++) { | |
char ch = Serial.read(); | |
code = code << 4; //make way for new char | |
if (ch >= '0' && ch <= '9') { | |
code += ch - '0'; | |
} else if (ch >= 'a' && ch <= 'f') { | |
code += ch - 'a' + 10; | |
} else if (ch >= 'A' & ch <= 'F') { | |
code += ch - 'A' + 10; | |
} else { | |
Serial.print("Unexpected hex char: "); | |
Serial.println(ch); | |
Serial.flush(); | |
return 0; | |
} | |
} | |
return code; | |
} | |
void sendIRCommand(char type, int code) { | |
switch(type) { | |
case SONY: | |
for (int i = 0; i < 6; i++) { | |
digitalWrite(IRLED_PIN, HIGH); // set the LED on | |
irsend.sendSony(code, 12); // Sony TV code | |
delay(100); | |
digitalWrite(IRLED_PIN, LOW); // set the LED off | |
} | |
break; | |
case RC5: | |
digitalWrite(IRLED_PIN, HIGH); // set the LED on | |
irsend.sendRC5(code, 12); | |
delay(100); | |
digitalWrite(IRLED_PIN, LOW); // set the LED off | |
break; | |
} | |
} | |
void loop() { | |
if (Serial.available() < 9) return; | |
char type = Serial.read(); | |
//Reads the extra 8 chars | |
unsigned long code = readCode(); | |
/* Debug | |
Serial.print("0x"); | |
Serial.println(code, HEX); | |
*/ | |
switch(type) { | |
case SONY: | |
case RC5: | |
sendIRCommand(type, code); | |
break; | |
case RF: | |
// Retransmit the signal 8 times ( == 2^3) on pin RFTRANSMITTER. Note: no object was created! | |
RemoteTransmitter::sendCode(RFTRANSMITTER_PIN, code, RF_PERIOD, 3); | |
break; | |
default: | |
Serial.print("Unexpected type: "); | |
Serial.println(type); | |
} | |
Serial.println("ok"); | |
Serial.flush(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment