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(" bits)");
-
}
-
-
void loop() {
-
if (ir_receiver.decode(&results)) {
55
dump(&results);
-
ir_receiver.resume();
-
}
-
}
-
First, we define an
IRrecv
object named
ir_receiver
that reads from pin 11. We
also define a
decode_result
object that we’ll use to store the attributes of
incoming infrared signals. In
setup
, we initialize the serial port, and we initialize
the infrared receiver by calling
enableIRIn
.
Then we define the
dump
method that formats and outputs the content of a
decode_result
object to the serial port.
decode_result
is one of the core data types
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
decode
to check whether we’ve received a
new signal. If yes, we call
dump
to output it to the serial port, and then 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. Figure 30, Capture the IR codes of a Samsung remote, on
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 • 206
report erratum • discuss
www.it-ebooks.info