|
| 1 | +#define DECODE_NEC |
| 2 | +#include <IRremote.hpp> |
| 3 | + |
| 4 | +#define IR_RECEIVE_PIN 11 |
| 5 | + |
| 6 | +#if !defined(STR_HELPER) |
| 7 | +#define STR_HELPER(x) #x |
| 8 | +#define STR(x) STR_HELPER(x) |
| 9 | +#endif |
| 10 | +//const int remotePin = 11; |
| 11 | + |
| 12 | +void setup() { |
| 13 | + Serial.begin(9600); |
| 14 | + while (!Serial) |
| 15 | + ; // Wait for Serial to become available. Is optimized away for some cores. |
| 16 | + // Just to know which program is running on my Arduino |
| 17 | + Serial.println(); |
| 18 | + Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version: " VERSION_IRREMOTE)); |
| 19 | + // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feed |
| 20 | + IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); |
| 21 | + Serial.print(F("Ready to receive IR signals of protocols: ")); |
| 22 | + printActiveIRProtocols(&Serial); |
| 23 | + Serial.println(F("at pin: " STR(IR_RECEIVE_PIN))); |
| 24 | + Serial.println(); |
| 25 | +} |
| 26 | + |
| 27 | +void loop() { |
| 28 | + /* |
| 29 | + * Check if received data is available and if yes, try to decode it. |
| 30 | + * Decoded result is in the IrReceiver.decodedIRData structure. |
| 31 | + * |
| 32 | + * E.g. command is in IrReceiver.decodedIRData.command |
| 33 | + * address is in command is in IrReceiver.decodedIRData.address |
| 34 | + * and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData |
| 35 | + */ |
| 36 | + if (IrReceiver.decode()) { |
| 37 | + // Print a summary of received data |
| 38 | + if (IrReceiver.decodedIRData.protocol == UNKNOWN) { |
| 39 | + Serial.println(F("Received noise or an unknown (or not yet enabled) protocol")); |
| 40 | + // We have an unknown protocol here, print extended info |
| 41 | + IrReceiver.printIRResultRawFormatted(&Serial, true); |
| 42 | + IrReceiver.resume(); // Do it here, to preserve raw data for printing with printIRResultRawFormatted() |
| 43 | + } else { |
| 44 | + IrReceiver.resume(); // Early enable receiving of the next IR frame |
| 45 | + IrReceiver.printIRResultShort(&Serial); |
| 46 | + //IrReceiver.printIRSendUsage(&Serial); |
| 47 | + } |
| 48 | + Serial.println(); |
| 49 | + |
| 50 | + // Finally, check the received data and perform actions according to the received command |
| 51 | + switch (IrReceiver.decodedIRData.command) { |
| 52 | + case 0x40: Serial.print("'OK'"); break; |
| 53 | + |
| 54 | + case 0x46: Serial.print("'Up'"); break; |
| 55 | + case 0x15: Serial.print("'Down'"); break; |
| 56 | + |
| 57 | + case 0x52: Serial.print("'0'"); break; |
| 58 | + case 0x16: Serial.print("'1'"); break; |
| 59 | + case 0x19: Serial.print("'2'"); break; |
| 60 | + |
| 61 | + case 0x42: Serial.print("'*'"); break; |
| 62 | + default: Serial.print("'?'"); |
| 63 | + } |
| 64 | + Serial.print("\n\n"); |
| 65 | + } |
| 66 | +} |
0 commit comments