Serial.println("MITSUBISHI");
-
}
else if
(protocol == SAMSUNG) {
-
Serial.println("SAMSUNG");
-
}
else if
(protocol == LG) {
-
Serial.println("LG");
45
}
-
Serial.print("Value:
-
Serial.print(results->value, HEX);
-
Serial.print("
(");
-
Serial.print(results->bits, DEC);
50
Serial.println("
-
}
-
-
void
loop() {
-
if
(ir_receiver.decode(&results)) {
55
dump(&results);
-
ir_receiver.resume();
-
}
-
}
-
First, we define an
also define a
decode_result
incoming infrared signals. In
the infrared receiver by calling
Then we define the
decode_result
object to the serial port.
of the IRremote library. It encapsulates data such as the protocol type, the
length of a command code, and the command code itself. In line 15, we read
the protocol type that has been used to encode the incoming signal. When
we receive a new signal, we output all of these attributes to the serial port.
The
loop
method is simple. We call
new signal. If yes, we call
resume
to wait for the next signal.
Compile and upload the sketch to your Arduino. Start the serial monitor and
point a remote control at the receiver. Push some of the remote s buttons and
see what happens.
page 207
shows happens when you point a recent Samsung remote at the
receiver and press menu, up, down, left, right, and play.
If you re using a remote from a different vendor, your results will differ.
Nearly all modern remotes send a unique 32-bit value for each command,
but there are exceptions, too. For example, Panasonic devices send not only
a command value, but also an address. Also, remote control behavior differs
regarding command repetition. If you press and hold a key on a Samsung
Chapter 12. Creating Your Own Universal Remote Control
");
bits)");
IRrecv
object named
ir_receiver
object that we ll use to store the attributes of
setup
, we initialize the serial port, and we initialize
enableIRIn
.
dump
method that formats and outputs the content of a
decode_result
decode
dump
to output it to the serial port, and then we call
Figure 30, Capture the IR codes of a Samsung remote, on
www.it-ebooks.info
that reads from pin 11. We
is one of the core data types
to check whether we ve received a
206
report erratum
discuss
Need help?
Do you have a question about the Arduino Uno and is the answer not in the manual?