Skip to content

Commit ae47741

Browse files
committed
Fixup old examples
Add new example
1 parent 07df68a commit ae47741

File tree

3 files changed

+175
-8
lines changed

3 files changed

+175
-8
lines changed

IRremote.h

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
#ifndef IRremote_h
1919
#define IRremote_h
2020

21+
//------------------------------------------------------------------------------
22+
// The ISR header contains several useful macros the user may wish to use
23+
//
24+
#include "IRremoteInt.h"
25+
2126
//------------------------------------------------------------------------------
2227
// Supported IR protocols
2328
// Each protocol you include costs memory and, during decode, costs time

examples/IRrecvDump/IRrecvDump.ino

+8-8
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,30 @@ void dump(decode_results *results) {
3131
int count = results->rawlen;
3232
if (results->decode_type == UNKNOWN) {
3333
Serial.print("Unknown encoding: ");
34-
}
34+
}
3535
else if (results->decode_type == NEC) {
3636
Serial.print("Decoded NEC: ");
37-
}
37+
}
3838
else if (results->decode_type == SONY) {
3939
Serial.print("Decoded SONY: ");
40-
}
40+
}
4141
else if (results->decode_type == RC5) {
4242
Serial.print("Decoded RC5: ");
43-
}
43+
}
4444
else if (results->decode_type == RC6) {
4545
Serial.print("Decoded RC6: ");
4646
}
47-
else if (results->decode_type == PANASONIC) {
47+
else if (results->decode_type == PANASONIC) {
4848
Serial.print("Decoded PANASONIC - Address: ");
49-
Serial.print(results->panasonicAddress,HEX);
49+
Serial.print(results->address,HEX);
5050
Serial.print(" Value: ");
5151
}
5252
else if (results->decode_type == LG) {
5353
Serial.print("Decoded LG: ");
5454
}
5555
else if (results->decode_type == JVC) {
5656
Serial.print("Decoded JVC: ");
57-
57+
5858
}
5959
else if (results->decode_type == AIWA_RC_T501) {
6060
Serial.print("Decoded AIWA RC T501: ");
@@ -73,7 +73,7 @@ void dump(decode_results *results) {
7373
for (int i = 0; i < count; i++) {
7474
if ((i % 2) == 1) {
7575
Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
76-
}
76+
}
7777
else {
7878
Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
7979
}
+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
//------------------------------------------------------------------------------
2+
// Include the IRremote library headers
3+
//
4+
#include <IRremote.h>
5+
#include <IRremoteInt.h>
6+
7+
//------------------------------------------------------------------------------
8+
// Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838)
9+
//
10+
IRrecv irrecv(6);
11+
12+
//+=============================================================================
13+
// Configure the Arduino
14+
//
15+
void setup ( )
16+
{
17+
Serial.begin(9600); // Status message will be sent to PC at 9600 baud
18+
irrecv.enableIRIn(); // Start the receiver
19+
}
20+
21+
//+=============================================================================
22+
// Display IR code
23+
//
24+
void ircode (decode_results *results)
25+
{
26+
// Panasonic has an Address
27+
if (results->decode_type == PANASONIC) {
28+
Serial.print(results->address, HEX);
29+
Serial.print(":");
30+
}
31+
32+
// Print Code
33+
Serial.print(results->value, HEX);
34+
}
35+
36+
//+=============================================================================
37+
// Display encoding type
38+
//
39+
void encoding (decode_results *results)
40+
{
41+
switch (results->decode_type) {
42+
default:
43+
case UNKNOWN: Serial.print("UNKNOWN"); break ;
44+
case NEC: Serial.print("NEC"); break ;
45+
case SONY: Serial.print("SONY"); break ;
46+
case RC5: Serial.print("RC5"); break ;
47+
case RC6: Serial.print("RC6"); break ;
48+
case DISH: Serial.print("DISH"); break ;
49+
case SHARP: Serial.print("SHARP"); break ;
50+
case JVC: Serial.print("JVC"); break ;
51+
case SANYO: Serial.print("SANYO"); break ;
52+
case MITSUBISHI: Serial.print("MITSUBISHI"); break ;
53+
case SAMSUNG: Serial.print("SAMSUNG"); break ;
54+
case LG: Serial.print("LG"); break ;
55+
case WHYNTER: Serial.print("WHYNTER"); break ;
56+
case AIWA_RC_T501: Serial.print("AIWA_RC_T501"); break ;
57+
case PANASONIC: Serial.print("PANASONIC"); break ;
58+
}
59+
}
60+
61+
//+=============================================================================
62+
// Dump out the decode_results structure.
63+
//
64+
void dumpInfo (decode_results *results)
65+
{
66+
// Check if the buffer overflowed
67+
if (results->overflow) {
68+
Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWLEN");
69+
return;
70+
}
71+
72+
// Show Encoding standard
73+
Serial.print("Encoding : ");
74+
encoding(results);
75+
Serial.println("");
76+
77+
// Show Code & length
78+
Serial.print("Code : ");
79+
ircode(results);
80+
Serial.print(" (");
81+
Serial.print(results->bits, DEC);
82+
Serial.println(" bits)");
83+
}
84+
85+
//+=============================================================================
86+
// Dump out the decode_results structure.
87+
//
88+
void dumpRaw (decode_results *results)
89+
{
90+
// Print Raw data
91+
Serial.print("Timing[");
92+
Serial.print(results->rawlen, DEC);
93+
Serial.println("]: ");
94+
Serial.print(" -");
95+
Serial.println(results->rawbuf[0] * USECPERTICK, DEC);
96+
for (int i = 1; i < results->rawlen; i++) {
97+
int x = results->rawbuf[i] * USECPERTICK;
98+
if (!(i & 1)) { // even
99+
Serial.print("-");
100+
if (x < 1000) Serial.print(" ") ;
101+
if (x < 100) Serial.print(" ") ;
102+
Serial.print(x, DEC);
103+
} else { // odd
104+
Serial.print(" ");
105+
Serial.print("+");
106+
if (x < 1000) Serial.print(" ") ;
107+
if (x < 100) Serial.print(" ") ;
108+
Serial.print(x, DEC);
109+
Serial.print(", ");
110+
}
111+
if (!(i%8)) Serial.println("");
112+
}
113+
Serial.println(""); // Newline
114+
}
115+
116+
//+=============================================================================
117+
// Dump out the decode_results structure.
118+
//
119+
void dumpCode (decode_results *results)
120+
{
121+
// Start declaration
122+
Serial.print("unsigned int "); // variable type
123+
Serial.print("rawData["); // array name
124+
Serial.print(results->rawlen + 1, DEC); // array size
125+
Serial.print("] = {"); // Start declaration
126+
127+
// Dump data
128+
for (int i = 0; i < results->rawlen; i++) {
129+
Serial.print(results->rawbuf[i], DEC);
130+
Serial.print(",");
131+
if (!(i&1)) Serial.print(" ");
132+
}
133+
134+
// End declaration
135+
Serial.print("0};"); // Turn LED off at the end
136+
137+
// Comment
138+
Serial.print(" // ");
139+
encoding(results);
140+
Serial.print(" ");
141+
ircode(results);
142+
143+
// Newline
144+
Serial.println("");
145+
}
146+
147+
//+=============================================================================
148+
// The repeating section of the code
149+
//
150+
void loop ( )
151+
{
152+
decode_results results; // Somewhere to store the results
153+
154+
if (irrecv.decode(&results)) { // Grab an IR code
155+
dumpInfo(&results); // Output the results
156+
dumpRaw(&results); // Output the results in RAW format
157+
dumpCode(&results); // Output the results as source code
158+
Serial.println(""); // Blank line between entries
159+
irrecv.resume(); // Prepare for the next value
160+
}
161+
}
162+

0 commit comments

Comments
 (0)