Skip to content

Instantly share code, notes, and snippets.

@mjdargen
Created June 30, 2020 02:58
Show Gist options
  • Save mjdargen/95aea6d3b0318306b1e149bb2aee3bb9 to your computer and use it in GitHub Desktop.
Save mjdargen/95aea6d3b0318306b1e149bb2aee3bb9 to your computer and use it in GitHub Desktop.
// Basic demo for IR remote/receiver
// include IR remote library
#include <IRremote.h>
// define pin and declare object
#define IR_RCVR_PIN 11
IRrecv irrecv(IR_RCVR_PIN);
// put your setup code here, to run once:
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// wait for serial port to connect. Needed for native USB port only
while (!Serial);
// start the IR receiver
irrecv.enableIRIn();
}
// put your main code here, to run repeatedly:
void loop() {
// special data type to store IR receiver results
decode_results results;
// if IR data to receive, it stores it into "results" and enters if-body
if (irrecv.decode(&results)) {
// translate the received value
// it is stored in results.value
// it is a "long" not an "int"
long val = results.value;
// long list of conditionals for decoding the IR values
// just keep the conditionals for the buttons you want to use
if (val == 0xFFA25D) {
Serial.println("POWER");
}
else if (val == 0xFF629D) {
Serial.println("MODE");
}
else if (val == 0xFFE21D) {
Serial.println("MUTE");
}
else if (val == 0xFF22DD) {
Serial.println("PLAY");
}
else if (val == 0xFF02FD) {
Serial.println("REWIND");
}
else if (val == 0xFFC23D) {
Serial.println("FAST FORWARD");
}
else if (val == 0xFFE01F) {
Serial.println("EQ");
}
else if (val == 0xFFA857) {
Serial.println("VOL-");
}
else if (val == 0xFF906F) {
Serial.println("VOL+");
}
else if (val == 0xFF6897) {
Serial.println("0");
}
else if (val == 0xFF9867) {
Serial.println("REPEAT");
}
else if (val == 0xFFB04F) {
Serial.println("USB SCAN");
}
else if (val == 0xFF30CF) {
Serial.println("1");
}
else if (val == 0xFF18E7) {
Serial.println("2");
}
else if (val == 0xFF7A85) {
Serial.println("3");
}
else if (val == 0xFF10EF) {
Serial.println("4");
}
else if (val == 0xFF38C7) {
Serial.println("5");
}
else if (val == 0xFF5AA5) {
Serial.println("6");
}
else if (val == 0xFF42BD) {
Serial.println("7");
}
else if (val == 0xFF4AB5) {
Serial.println("8");
}
else if (val == 0xFF52AD) {
Serial.println("9");
}
else if (val == 0xFFFFFFFF) {
Serial.println("Repeat button pressed detected.");
}
else {
Serial.println("Misread: not recognized");
}
// should delay so it doesn't keep getting the same button press
delay(500);
// prepare for the next IR receiver value
irrecv.resume();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment