#include <IRremote.h>
#include <LiquidCrystal.h>
#define PIN_RECEIVER 4
IRrecv receiver(PIN_RECEIVER);
LiquidCrystal lcd(0x27, 16, 2);
void setup() {
lcd.begin(16, 2);
lcd.print("<press a button>");
receiver.enableIRIn(); // Start the receiver
}
void loop() {
// Checks received an IR signal
if (receiver.decode()) {
translateIR();
receiver.resume(); // Receive the next value
}
}
void lcdPrint(char* text) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("button pressed:");
lcd.setCursor(0, 1);
lcd.print(text);
lcd.print(" code: ");
lcd.print(receiver.decodedIRData.command);
}
void translateIR() {
// Takes command based on IR code received
switch (receiver.decodedIRData.command) {
case 162:
lcdPrint("POWER");
break;
// ... (other cases)
default:
lcd.clear();
lcd.print(receiver.decodedIRData.command);
lcd.print(" other button");
}
}