that at the time of this writing, the IRremote library is able to decode remote
controls from Sanyo, Mitsubishi, and LG, but it doesn’t support sending
commands to devices from these manufacturers.
After we’ve established the basis, we can implement all commands with a
single function call, so implementing
power
,
menu
,
play
, and so on is a piece of
cake.
Using the
TvRemote
class is easy, too. In the following sketch, we use it to
control a Samsung TV from the Arduino’s serial monitor:
RemoteControl/TvRemote/TvRemote.ino
const unsigned int BAUD_RATE = 9600;
Line 1
-
TvRemote tv;
-
String command = "";
-
boolean input_available = false;
5
-
void setup() {
-
Serial.begin(BAUD_RATE);
-
}
-
10
void serialEvent() {
-
while (Serial.available()) {
-
const char c = Serial.read();
-
if (c == '\n')
-
input_available = true;
15
else
-
command += c;
-
}
-
}
-
20
void loop() {
-
if (input_available) {
-
Serial.print("Received command: ");
-
Serial.println(command);
-
if (command == "guide") tv.guide();
25
else if (command == "power") tv.power();
-
else if (command == "tools") tv.tools();
-
else if (command == "source") tv.source();
-
else if (command == "info") tv.info();
-
else if (command == "hdmi") tv.hdmi();
30
else if (command == "zero") tv.zero();
-
else if (command == "one") tv.one();
-
else if (command == "two") tv.two();
-
else if (command == "three") tv.three();
-
else if (command == "four") tv.four();
35
else if (command == "five") tv.five();
-
else if (command == "six") tv.six();
-
else if (command == "seven") tv.seven();
-
Chapter 12. Creating Your Own Universal Remote Control • 210
report erratum • discuss
www.it-ebooks.info