Created
February 18, 2018 18:42
-
-
Save microcontrollershub/6becd854a2885059711970278f5808f9 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 <SoftwareSerial.h> | |
IRsend irsend; | |
SoftwareSerial BTSerial(10, 11); // RX | TX | |
String ReceivedString_1 = "turn on TV"; | |
String ReceivedString_2 = "turn off TV"; | |
String ReceivedString_3 = "mute"; | |
String ReceivedString_4 = "unmute"; | |
String ReceivedString_5 = "volume up"; | |
String ReceivedString_6 = "volume down"; | |
String ReceivedString_7 = "channel up"; | |
String ReceivedString_8 = "channel down"; | |
void setup() | |
{ | |
Serial.begin(9600); | |
BTSerial.begin(9600); // HC-05 default speed in AT command more | |
} | |
void loop() | |
{ | |
if (BTSerial.available()) | |
{ | |
String ReceivedString = BTSerial.readString(); | |
long Command = Get_Command(ReceivedString); | |
Send_Command(Command); | |
Serial.println("****************************************************"); | |
Serial.println(ReceivedString); | |
Serial.println(Command,HEX); | |
Serial.println("****************************************************"); | |
} | |
} | |
long Get_Command(String ReceivedString) | |
{ | |
byte data = 0x0000; | |
if (ReceivedString_1 == ReceivedString) | |
return 0x18B5; | |
else if (ReceivedString_2 == ReceivedString) | |
return 0x08B5; | |
else if (ReceivedString_3 == ReceivedString) | |
return 0x18B9; | |
else if (ReceivedString_4 == ReceivedString) | |
return 0x18B9; | |
else if (ReceivedString_5 == ReceivedString) | |
return 0x18C2; | |
else if (ReceivedString_6 == ReceivedString) | |
return 0x1894; | |
else if (ReceivedString_7 == ReceivedString) | |
return 0x189D; | |
else if (ReceivedString_8 == ReceivedString) | |
return 0x1897; | |
else | |
return 0x0000; | |
} | |
void Send_Command(long data) | |
{ | |
for (int i = 0; i < 5; i++) | |
{ | |
irsend.sendRC5(data, 13); | |
delay(40); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment