Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Lilnija_29012017 NucleoF042K6_IRReceiver
examples/IRrecvDumpV2/IRrecvDumpV2.ino@1:370967a90abb, 2016-01-23 (annotated)
- Committer:
- yuhki50
- Date:
- Sat Jan 23 15:25:05 2016 +0900
- Revision:
- 1:370967a90abb
- Parent:
- 0:70c8e56bac45
remove files that depend on Arduino
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yuhki50 | 0:70c8e56bac45 | 1 | //------------------------------------------------------------------------------ |
| yuhki50 | 0:70c8e56bac45 | 2 | // Include the IRremote library header |
| yuhki50 | 0:70c8e56bac45 | 3 | // |
| yuhki50 | 0:70c8e56bac45 | 4 | #include <IRremote.h> |
| yuhki50 | 0:70c8e56bac45 | 5 | |
| yuhki50 | 0:70c8e56bac45 | 6 | //------------------------------------------------------------------------------ |
| yuhki50 | 0:70c8e56bac45 | 7 | // Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838) |
| yuhki50 | 0:70c8e56bac45 | 8 | // |
| yuhki50 | 0:70c8e56bac45 | 9 | int recvPin = 11; |
| yuhki50 | 0:70c8e56bac45 | 10 | IRrecv irrecv(recvPin); |
| yuhki50 | 0:70c8e56bac45 | 11 | |
| yuhki50 | 0:70c8e56bac45 | 12 | //+============================================================================= |
| yuhki50 | 0:70c8e56bac45 | 13 | // Configure the Arduino |
| yuhki50 | 0:70c8e56bac45 | 14 | // |
| yuhki50 | 0:70c8e56bac45 | 15 | void setup ( ) |
| yuhki50 | 0:70c8e56bac45 | 16 | { |
| yuhki50 | 0:70c8e56bac45 | 17 | Serial.begin(9600); // Status message will be sent to PC at 9600 baud |
| yuhki50 | 0:70c8e56bac45 | 18 | irrecv.enableIRIn(); // Start the receiver |
| yuhki50 | 0:70c8e56bac45 | 19 | } |
| yuhki50 | 0:70c8e56bac45 | 20 | |
| yuhki50 | 0:70c8e56bac45 | 21 | //+============================================================================= |
| yuhki50 | 0:70c8e56bac45 | 22 | // Display IR code |
| yuhki50 | 0:70c8e56bac45 | 23 | // |
| yuhki50 | 0:70c8e56bac45 | 24 | void ircode (decode_results *results) |
| yuhki50 | 0:70c8e56bac45 | 25 | { |
| yuhki50 | 0:70c8e56bac45 | 26 | // Panasonic has an Address |
| yuhki50 | 0:70c8e56bac45 | 27 | if (results->decode_type == PANASONIC) { |
| yuhki50 | 0:70c8e56bac45 | 28 | Serial.print(results->address, HEX); |
| yuhki50 | 0:70c8e56bac45 | 29 | Serial.print(":"); |
| yuhki50 | 0:70c8e56bac45 | 30 | } |
| yuhki50 | 0:70c8e56bac45 | 31 | |
| yuhki50 | 0:70c8e56bac45 | 32 | // Print Code |
| yuhki50 | 0:70c8e56bac45 | 33 | Serial.print(results->value, HEX); |
| yuhki50 | 0:70c8e56bac45 | 34 | } |
| yuhki50 | 0:70c8e56bac45 | 35 | |
| yuhki50 | 0:70c8e56bac45 | 36 | //+============================================================================= |
| yuhki50 | 0:70c8e56bac45 | 37 | // Display encoding type |
| yuhki50 | 0:70c8e56bac45 | 38 | // |
| yuhki50 | 0:70c8e56bac45 | 39 | void encoding (decode_results *results) |
| yuhki50 | 0:70c8e56bac45 | 40 | { |
| yuhki50 | 0:70c8e56bac45 | 41 | switch (results->decode_type) { |
| yuhki50 | 0:70c8e56bac45 | 42 | default: |
| yuhki50 | 0:70c8e56bac45 | 43 | case UNKNOWN: Serial.print("UNKNOWN"); break ; |
| yuhki50 | 0:70c8e56bac45 | 44 | case NEC: Serial.print("NEC"); break ; |
| yuhki50 | 0:70c8e56bac45 | 45 | case SONY: Serial.print("SONY"); break ; |
| yuhki50 | 0:70c8e56bac45 | 46 | case RC5: Serial.print("RC5"); break ; |
| yuhki50 | 0:70c8e56bac45 | 47 | case RC6: Serial.print("RC6"); break ; |
| yuhki50 | 0:70c8e56bac45 | 48 | case DISH: Serial.print("DISH"); break ; |
| yuhki50 | 0:70c8e56bac45 | 49 | case SHARP: Serial.print("SHARP"); break ; |
| yuhki50 | 0:70c8e56bac45 | 50 | case JVC: Serial.print("JVC"); break ; |
| yuhki50 | 0:70c8e56bac45 | 51 | case SANYO: Serial.print("SANYO"); break ; |
| yuhki50 | 0:70c8e56bac45 | 52 | case MITSUBISHI: Serial.print("MITSUBISHI"); break ; |
| yuhki50 | 0:70c8e56bac45 | 53 | case SAMSUNG: Serial.print("SAMSUNG"); break ; |
| yuhki50 | 0:70c8e56bac45 | 54 | case LG: Serial.print("LG"); break ; |
| yuhki50 | 0:70c8e56bac45 | 55 | case WHYNTER: Serial.print("WHYNTER"); break ; |
| yuhki50 | 0:70c8e56bac45 | 56 | case AIWA_RC_T501: Serial.print("AIWA_RC_T501"); break ; |
| yuhki50 | 0:70c8e56bac45 | 57 | case PANASONIC: Serial.print("PANASONIC"); break ; |
| yuhki50 | 0:70c8e56bac45 | 58 | case DENON: Serial.print("Denon"); break ; |
| yuhki50 | 0:70c8e56bac45 | 59 | } |
| yuhki50 | 0:70c8e56bac45 | 60 | } |
| yuhki50 | 0:70c8e56bac45 | 61 | |
| yuhki50 | 0:70c8e56bac45 | 62 | //+============================================================================= |
| yuhki50 | 0:70c8e56bac45 | 63 | // Dump out the decode_results structure. |
| yuhki50 | 0:70c8e56bac45 | 64 | // |
| yuhki50 | 0:70c8e56bac45 | 65 | void dumpInfo (decode_results *results) |
| yuhki50 | 0:70c8e56bac45 | 66 | { |
| yuhki50 | 0:70c8e56bac45 | 67 | // Check if the buffer overflowed |
| yuhki50 | 0:70c8e56bac45 | 68 | if (results->overflow) { |
| yuhki50 | 0:70c8e56bac45 | 69 | Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWLEN"); |
| yuhki50 | 0:70c8e56bac45 | 70 | return; |
| yuhki50 | 0:70c8e56bac45 | 71 | } |
| yuhki50 | 0:70c8e56bac45 | 72 | |
| yuhki50 | 0:70c8e56bac45 | 73 | // Show Encoding standard |
| yuhki50 | 0:70c8e56bac45 | 74 | Serial.print("Encoding : "); |
| yuhki50 | 0:70c8e56bac45 | 75 | encoding(results); |
| yuhki50 | 0:70c8e56bac45 | 76 | Serial.println(""); |
| yuhki50 | 0:70c8e56bac45 | 77 | |
| yuhki50 | 0:70c8e56bac45 | 78 | // Show Code & length |
| yuhki50 | 0:70c8e56bac45 | 79 | Serial.print("Code : "); |
| yuhki50 | 0:70c8e56bac45 | 80 | ircode(results); |
| yuhki50 | 0:70c8e56bac45 | 81 | Serial.print(" ("); |
| yuhki50 | 0:70c8e56bac45 | 82 | Serial.print(results->bits, DEC); |
| yuhki50 | 0:70c8e56bac45 | 83 | Serial.println(" bits)"); |
| yuhki50 | 0:70c8e56bac45 | 84 | } |
| yuhki50 | 0:70c8e56bac45 | 85 | |
| yuhki50 | 0:70c8e56bac45 | 86 | //+============================================================================= |
| yuhki50 | 0:70c8e56bac45 | 87 | // Dump out the decode_results structure. |
| yuhki50 | 0:70c8e56bac45 | 88 | // |
| yuhki50 | 0:70c8e56bac45 | 89 | void dumpRaw (decode_results *results) |
| yuhki50 | 0:70c8e56bac45 | 90 | { |
| yuhki50 | 0:70c8e56bac45 | 91 | // Print Raw data |
| yuhki50 | 0:70c8e56bac45 | 92 | Serial.print("Timing["); |
| yuhki50 | 0:70c8e56bac45 | 93 | Serial.print(results->rawlen-1, DEC); |
| yuhki50 | 0:70c8e56bac45 | 94 | Serial.println("]: "); |
| yuhki50 | 0:70c8e56bac45 | 95 | |
| yuhki50 | 0:70c8e56bac45 | 96 | for (int i = 1; i < results->rawlen; i++) { |
| yuhki50 | 0:70c8e56bac45 | 97 | unsigned long x = results->rawbuf[i] * USECPERTICK; |
| yuhki50 | 0:70c8e56bac45 | 98 | if (!(i & 1)) { // even |
| yuhki50 | 0:70c8e56bac45 | 99 | Serial.print("-"); |
| yuhki50 | 0:70c8e56bac45 | 100 | if (x < 1000) Serial.print(" ") ; |
| yuhki50 | 0:70c8e56bac45 | 101 | if (x < 100) Serial.print(" ") ; |
| yuhki50 | 0:70c8e56bac45 | 102 | Serial.print(x, DEC); |
| yuhki50 | 0:70c8e56bac45 | 103 | } else { // odd |
| yuhki50 | 0:70c8e56bac45 | 104 | Serial.print(" "); |
| yuhki50 | 0:70c8e56bac45 | 105 | Serial.print("+"); |
| yuhki50 | 0:70c8e56bac45 | 106 | if (x < 1000) Serial.print(" ") ; |
| yuhki50 | 0:70c8e56bac45 | 107 | if (x < 100) Serial.print(" ") ; |
| yuhki50 | 0:70c8e56bac45 | 108 | Serial.print(x, DEC); |
| yuhki50 | 0:70c8e56bac45 | 109 | if (i < results->rawlen-1) Serial.print(", "); //',' not needed for last one |
| yuhki50 | 0:70c8e56bac45 | 110 | } |
| yuhki50 | 0:70c8e56bac45 | 111 | if (!(i % 8)) Serial.println(""); |
| yuhki50 | 0:70c8e56bac45 | 112 | } |
| yuhki50 | 0:70c8e56bac45 | 113 | Serial.println(""); // Newline |
| yuhki50 | 0:70c8e56bac45 | 114 | } |
| yuhki50 | 0:70c8e56bac45 | 115 | |
| yuhki50 | 0:70c8e56bac45 | 116 | //+============================================================================= |
| yuhki50 | 0:70c8e56bac45 | 117 | // Dump out the decode_results structure. |
| yuhki50 | 0:70c8e56bac45 | 118 | // |
| yuhki50 | 0:70c8e56bac45 | 119 | void dumpCode (decode_results *results) |
| yuhki50 | 0:70c8e56bac45 | 120 | { |
| yuhki50 | 0:70c8e56bac45 | 121 | // Start declaration |
| yuhki50 | 0:70c8e56bac45 | 122 | Serial.print("unsigned int "); // variable type |
| yuhki50 | 0:70c8e56bac45 | 123 | Serial.print("rawData["); // array name |
| yuhki50 | 0:70c8e56bac45 | 124 | Serial.print(results->rawlen - 1, DEC); // array size |
| yuhki50 | 0:70c8e56bac45 | 125 | Serial.print("] = {"); // Start declaration |
| yuhki50 | 0:70c8e56bac45 | 126 | |
| yuhki50 | 0:70c8e56bac45 | 127 | // Dump data |
| yuhki50 | 0:70c8e56bac45 | 128 | for (int i = 1; i < results->rawlen; i++) { |
| yuhki50 | 0:70c8e56bac45 | 129 | Serial.print(results->rawbuf[i] * USECPERTICK, DEC); |
| yuhki50 | 0:70c8e56bac45 | 130 | if ( i < results->rawlen-1 ) Serial.print(","); // ',' not needed on last one |
| yuhki50 | 0:70c8e56bac45 | 131 | if (!(i & 1)) Serial.print(" "); |
| yuhki50 | 0:70c8e56bac45 | 132 | } |
| yuhki50 | 0:70c8e56bac45 | 133 | |
| yuhki50 | 0:70c8e56bac45 | 134 | // End declaration |
| yuhki50 | 0:70c8e56bac45 | 135 | Serial.print("};"); // |
| yuhki50 | 0:70c8e56bac45 | 136 | |
| yuhki50 | 0:70c8e56bac45 | 137 | // Comment |
| yuhki50 | 0:70c8e56bac45 | 138 | Serial.print(" // "); |
| yuhki50 | 0:70c8e56bac45 | 139 | encoding(results); |
| yuhki50 | 0:70c8e56bac45 | 140 | Serial.print(" "); |
| yuhki50 | 0:70c8e56bac45 | 141 | ircode(results); |
| yuhki50 | 0:70c8e56bac45 | 142 | |
| yuhki50 | 0:70c8e56bac45 | 143 | // Newline |
| yuhki50 | 0:70c8e56bac45 | 144 | Serial.println(""); |
| yuhki50 | 0:70c8e56bac45 | 145 | |
| yuhki50 | 0:70c8e56bac45 | 146 | // Now dump "known" codes |
| yuhki50 | 0:70c8e56bac45 | 147 | if (results->decode_type != UNKNOWN) { |
| yuhki50 | 0:70c8e56bac45 | 148 | |
| yuhki50 | 0:70c8e56bac45 | 149 | // Some protocols have an address |
| yuhki50 | 0:70c8e56bac45 | 150 | if (results->decode_type == PANASONIC) { |
| yuhki50 | 0:70c8e56bac45 | 151 | Serial.print("unsigned int addr = 0x"); |
| yuhki50 | 0:70c8e56bac45 | 152 | Serial.print(results->address, HEX); |
| yuhki50 | 0:70c8e56bac45 | 153 | Serial.println(";"); |
| yuhki50 | 0:70c8e56bac45 | 154 | } |
| yuhki50 | 0:70c8e56bac45 | 155 | |
| yuhki50 | 0:70c8e56bac45 | 156 | // All protocols have data |
| yuhki50 | 0:70c8e56bac45 | 157 | Serial.print("unsigned int data = 0x"); |
| yuhki50 | 0:70c8e56bac45 | 158 | Serial.print(results->value, HEX); |
| yuhki50 | 0:70c8e56bac45 | 159 | Serial.println(";"); |
| yuhki50 | 0:70c8e56bac45 | 160 | } |
| yuhki50 | 0:70c8e56bac45 | 161 | } |
| yuhki50 | 0:70c8e56bac45 | 162 | |
| yuhki50 | 0:70c8e56bac45 | 163 | //+============================================================================= |
| yuhki50 | 0:70c8e56bac45 | 164 | // The repeating section of the code |
| yuhki50 | 0:70c8e56bac45 | 165 | // |
| yuhki50 | 0:70c8e56bac45 | 166 | void loop ( ) |
| yuhki50 | 0:70c8e56bac45 | 167 | { |
| yuhki50 | 0:70c8e56bac45 | 168 | decode_results results; // Somewhere to store the results |
| yuhki50 | 0:70c8e56bac45 | 169 | |
| yuhki50 | 0:70c8e56bac45 | 170 | if (irrecv.decode(&results)) { // Grab an IR code |
| yuhki50 | 0:70c8e56bac45 | 171 | dumpInfo(&results); // Output the results |
| yuhki50 | 0:70c8e56bac45 | 172 | dumpRaw(&results); // Output the results in RAW format |
| yuhki50 | 0:70c8e56bac45 | 173 | dumpCode(&results); // Output the results as source code |
| yuhki50 | 0:70c8e56bac45 | 174 | Serial.println(""); // Blank line between entries |
| yuhki50 | 0:70c8e56bac45 | 175 | irrecv.resume(); // Prepare for the next value |
| yuhki50 | 0:70c8e56bac45 | 176 | } |
| yuhki50 | 0:70c8e56bac45 | 177 | } |