Skip to content

Instantly share code, notes, and snippets.

@dbarrerap
Created October 1, 2016 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbarrerap/fc8c11da3f34965b8627bc81f8295f30 to your computer and use it in GitHub Desktop.
Save dbarrerap/fc8c11da3f34965b8627bc81f8295f30 to your computer and use it in GitHub Desktop.
#include <IRremote.h>
#include <SoftwareSerial.h>
#define POWER 0x2FD48B7
#define SOURCE 0x2FDF00F
#define UP 0x2FD41BE
#define DOWN 0x2FDC13E
#define OK 0x2FD916E
#define BAUD_RATE 9600
#define BITS 32
SoftwareSerial RC(4, 2);
IRsend irsend;
String command = "";
void setup() {
// put your setup code here, to run once:
Serial.begin(BAUD_RATE);
RC.begin(BAUD_RATE);
delay(500);
}
void loop() {
// put your main code here, to run repeatedly:
if (RC.available() > 0)
{
command = RC.readStringUntil('\n');
Serial.println(command);
sendCommand();
}
if (Serial.available() > 0)
{
command = Serial.readStringUntil('\n');
sendCommand();
}
}
void sendCommand() {
Serial.println("sendCommand");
if (command == "pow") {
RC.print("POWER");
irsend.sendNEC(POWER, BITS);
} else if (command == "t2h") {
RC.print("TV2HDMI");
// SOURCE - UP - UP - OK
irsend.sendNEC(SOURCE, BITS);
delay(100);
irsend.sendNEC(UP, BITS);
delay(100);
irsend.sendNEC(UP, BITS);
delay(100);
irsend.sendNEC(OK, BITS);
delay(100);
} else if (command == "h2t") {
RC.print("HDMI2TV");
// SOURCE - DOWN - DOWN - OK
irsend.sendNEC(SOURCE, BITS);
delay(100);
irsend.sendNEC(DOWN, BITS);
delay(100);
irsend.sendNEC(DOWN, BITS);
delay(100);
irsend.sendNEC(OK, BITS);
delay(100);
} else {
String msg = "Command not recognized";
Serial.print(msg);
RC.print(msg);
}
RC.print("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment