Created
April 9, 2021 18:35
-
-
Save bennamallory/c6fb11812c6103fa63895268db08cdaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* SimpleReceiver.cpp | |
* | |
* Demonstrates receiving NEC IR codes with IRrecv | |
* | |
* Copyright (C) 2020-2021 Armin Joachimsmeyer | |
* armin.joachimsmeyer@gmail.com | |
* | |
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. | |
* | |
* MIT License | |
*/ | |
/* | |
* Specify which protocol(s) should be used for decoding. | |
* If no protocol is defined, all protocols are active. | |
*/ | |
#include <Arduino.h> | |
#include <IRremote.h> | |
int IR_RECEIVE_PIN = 12; | |
void setup() { | |
Serial.begin(9600); | |
// Just to know which program is running on my Arduino | |
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); | |
/* | |
* Start the receiver, enable feedback LED and take LED feedback pin from the internal boards definition | |
*/ | |
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); | |
Serial.println(F("Ready to receive IR signals at pin ")); | |
Serial.println("PIN: " + IR_RECEIVE_PIN); | |
Serial.println("setup"); | |
} | |
void loop() { | |
/* | |
* Check if received data is available and if yes, try to decode it. | |
* Decoded result is in the IrReceiver.decodedIRData structure. | |
* | |
* E.g. command is in IrReceiver.decodedIRData.command | |
* address is in command is in IrReceiver.decodedIRData.address | |
* and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData | |
*/ | |
if (IrReceiver.decode()) { | |
// Print a short summary of received data | |
IrReceiver.printIRResultShort(&Serial); | |
if (IrReceiver.decodedIRData.protocol == UNKNOWN) { | |
// We have an unknown protocol here, print more info | |
IrReceiver.printIRResultRawFormatted(&Serial, true); | |
} | |
Serial.println(); | |
/* | |
* !!!Important!!! Enable receiving of the next value, | |
* since receiving has stopped after the end of the current received data packet. | |
*/ | |
IrReceiver.resume(); // Enable receiving of the next value | |
/* | |
* Finally, check the received data and perform actions according to the received command | |
*/ | |
if (IrReceiver.decodedIRData.command == 0x10) { | |
Serial.println("hello"); | |
} else if (IrReceiver.decodedIRData.command == 0x45) { | |
Serial.println("second"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment