So I tried using the sample code for the IR Remote from the tutorial and no matter what I did I could not get it to work. I stumbled across a bit of code that would decode HEX number for each button. I then wrote the code below to produce an output in the serial monitor. It is not pretty but it gets the job done. I would like to get others thoughts on this bit of code.
#include "IRremote.h"
IRrecv IR(11);
int ledPin = 8;
void setup()
{
IR.enableIRIn();
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(IR.decode())
{
if(IR.decodedIRData.decodedRawData == 0xBA45FF00){Serial.println("POWER");}
if (IR.decodedIRData.decodedRawData ==0xB847FF00) {Serial.println("FUNC/STOP");}
if (IR.decodedIRData.decodedRawData == 0xB946FF00) {Serial.println("VOL+");}
if (IR.decodedIRData.decodedRawData == 0xBB44FF00) {Serial.println("FAST BACK");}
if (IR.decodedIRData.decodedRawData == 0xBF40FF00) {Serial.println("PAUSE");}
if (IR.decodedIRData.decodedRawData == 0xBC43FF00) {Serial.println("FAST FORWARD");}
if (IR.decodedIRData.decodedRawData == 0xF807FF00) {Serial.println("DOWN");}
if (IR.decodedIRData.decodedRawData == 0xEA15FF00) {Serial.println("VOL-");}
if (IR.decodedIRData.decodedRawData == 0xF609FF00) {Serial.println("UP");}
if (IR.decodedIRData.decodedRawData == 0xE619FF00) {Serial.println("EQ");}
if (IR.decodedIRData.decodedRawData == 0xF20DFF00) {Serial.println("ST/REPT");}
if (IR.decodedIRData.decodedRawData == 0xE916FF00) {Serial.println("0");}
if(IR.decodedIRData.decodedRawData == 0xF30CFF00) {Serial.println("1");}
if(IR.decodedIRData.decodedRawData == 0xE718FF00) {Serial.println("2");}
if(IR.decodedIRData.decodedRawData == 0xA15EFF00) {Serial.println("3");}
if(IR.decodedIRData.decodedRawData == 0xF708FF00) {Serial.println("4");}
if(IR.decodedIRData.decodedRawData == 0xE31CFF00) {Serial.println("5");}
if(IR.decodedIRData.decodedRawData == 0xA55AFF00) {Serial.println("6");}
if(IR.decodedIRData.decodedRawData == 0xBD42FF00) {Serial.println("7");}
if(IR.decodedIRData.decodedRawData == 0xAD52FF00) {Serial.println("8");}
if(IR.decodedIRData.decodedRawData == 0xB54AFF00) {Serial.println("9");}
delay(1000);
IR.resume();
}
}
I apologize for the confusion. The original code I posted that is nothing like the tutorial produces the desired result by printing the designation of the button in the serial monitor when the button is pressed. The code you gave me which is very similar to the code in the tutorial does not work for me and I cannot quite figure out why. I also want to know if there is anything wrong with the way I did it in the code I posted. Thank you for your time. I am very new to this and coding.
nothing wrong if it works. if you compare you will note that i have replaced if construction with switch construction, they are working identical, looks better. the second thing i made the received data is half shorter by removing similar part "0xFF00". it save processor time. last thing - delay() is removed.
but in no place of code is serial output "?" and if you see it than something wrong with setup. could you show picture from serial monitor?