Skip to content

Instantly share code, notes, and snippets.

@blacklight
Last active October 22, 2019 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blacklight/635e7fa42940539ccc3edacc6135afce to your computer and use it in GitHub Desktop.
Save blacklight/635e7fa42940539ccc3edacc6135afce to your computer and use it in GitHub Desktop.
Infrared receiver sketch for Arduino
#include <IRremote.h>
#define IR_REPEAT 0xFFFFFFFF
const int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned int latest_value = 0;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}
void loop(){
if (irrecv.decode(&results)){
if (results.value && results.value != IR_REPEAT && results.value != latest_value) {
Serial.print("{\"ir\":");
Serial.print(results.value, HEX);
Serial.println("}");
}
latest_value = results.value;
irrecv.resume();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment