Decoding IR Control Signals
#include
const int RECV_PIN = 2;
const int NUM_OF_BUTS
= 21;
long BUTTON_CODES[NUM_OF_BUTS] = {
0xE0E08877, //button 0
0xE0E020DF, //button 1
0xE0E0A05F, //button 2
0xE0E0609F, //button 3
0xE0E010EF, //button 4
0xE0E0906F, //button 5
0xE0E050AF, //button 6
0xE0E030CF, //button 7
0xE0E0B04F, //button 8
0xE0E0708F, //button 9
0xE0E08679, //button 100+/DOWN
0xE0E006F9, //button 200+/UP
0xE0E0D02F, //button VOL-
0xE0E0E01F, //button VOL+
0xE0E016E9, //button EQ/MENU
0xE0E0A659, //button PREV/LEFT
0xE0E046B9, //button NEXT/RIGHT
0xE0E0F00F, //button PAUSE/MUTE
0xE0E008F7, //button CH-
0xE0E048B7, //button CH+
0xE0E040BF //button CH/POWER
};
String BUTTON_NAMES[NUM_OF_BUTS] = {
"0","1","2","3","4","5","6","7","8","9",
"100+/DOWN","200+/UP","VOL-","VOL+",
"EQ/MENU","PREV/LEFT","NEXT/RIGTH",
"PAUSE/MUTE","CH-","CH+","CH/POWER"
};
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
//Serial.println(results.value, HEX);
int button_id = findButton(results.value);
if(button_id <0){
Serial.println("Unknown button is pressed!");
} else{
Serial.print("Button ");
Serial.print(BUTTON_NAMES[button_id]);
Serial.println(" is pressed!");
}
irrecv.resume(); // Receive the next value
}
}
int findButton(long val){
for(int i = 0; i < NUM_OF_BUTS; i++){
if(val == BUTTON_CODES[i]) return i;
}
return -1;
}