/*
Project: Basic IR Tester
Description: Displays the "key name", decoded code,
protocol type, and raw data from the
Wokwi NEC IR remote
Creation date: 3/30/23
Author: AnonEngineering
License: https://en.wikipedia.org/wiki/Beerware
*/
#include <IRremote.hpp>
#include <LiquidCrystal_I2C.h>
const int RX_PIN = 2;
//const int LED_PIN = 13;
const int MAX_KEYS = 20;
const byte KEY_CODES[MAX_KEYS] = {
/* see https://docs.wokwi.com/parts/wokwi-ir-remote */
162, 226, 34, 2, 194,
224, 168, 144, 152, 176,
104, 48, 24, 122, 16,
56, 90, 66, 74, 82
};
const char KEY_NAMES[][MAX_KEYS] = {
/* see remote */
"Power", "Menu", "Test", "Plus", "Back",
"Prev", "Play", "Next", "Minus", "C",
"0", "1", "2", "3", "4",
"5", "6", "7", "8", "9"
};
//IRrecv receiver(RX_PIN);
LiquidCrystal_I2C lcd(0x27, 20, 4);
char* getKeyName() {
bool isCodeFound = false;
char* keyName;
for (int keyIdx = 0; keyIdx < MAX_KEYS; keyIdx++) {
if (KEY_CODES[keyIdx] == IrReceiver.decodedIRData.command) {
//if (KEY_CODES[keyIdx] == 999) { // for test
keyName = KEY_NAMES[keyIdx];
isCodeFound = true;
}
}
if (!isCodeFound) {
keyName = "Unknown";
}
return keyName;
}
void showKeyData(char* keyText) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Key : ");
lcd.print(keyText);
lcd.setCursor(0, 1);
lcd.print("Code: ");
lcd.print(IrReceiver.decodedIRData.command);
lcd.setCursor(0, 2);
lcd.print("Type: ");
lcd.print(IrReceiver.getProtocolString());
lcd.setCursor(0, 3);
lcd.print("Data: ");
lcd.print(IrReceiver.decodedIRData.decodedRawData, HEX); // little Endian
}
void showSplash() {
lcd.setCursor(3, 0);
lcd.print("IR Tester v1.00");
Serial.print("IRremote v");
Serial.println(VERSION_IRREMOTE);
lcd.setCursor(4, 2);
lcd.print("Press any key");
lcd.setCursor(6, 3);
lcd.print("to begin");
}
void setup() {
Serial.begin(9600);
lcd.begin(20, 4);
lcd.backlight();
//pinMode(LED_PIN, OUTPUT);
//receiver.enableIRIn(); // start the receiver
IrReceiver.begin(RX_PIN, ENABLE_LED_FEEDBACK);
showSplash();
}
void loop() {
if (IrReceiver.decode()) { // we received IR
Serial.println(IrReceiver.decodedIRData.command); // for test
//digitalWrite(LED_PIN, HIGH);
showKeyData(getKeyName()); // get key name, show key data
IrReceiver.resume(); // prepare for the next IR
} else {
//digitalWrite(LED_PIN, LOW);
}
}