Hi, I am trying to build something similar to one of the features on a flipper zero, the feature I am trying to recreate is the one where you can read an IR code save it, and then transmit a copy. I am using an IR receiver and an IR transmitter paired with 5 buttons with different purposes (these purposes are described in the code), a potentiometer (used to go through 255 addresses of EEPROM), and lastly as a form of interface an LCD with I2C. I have a picture of the wiring diagram (the red LED is an IR transmitter) below so that it is easier to understand, for the record the code published is not finished as I focused on one issue at a time. Now for the actual problem, the issue with all of this is that I haven't found a way to properly save the HEX codes on EEPROM. This is a problem because I cannot transmit the codes if they are not stored on the EEPROM. what would be best is that when you press the button connected to pin 10 the receiver collects codes and then by pressing the button connected to pin 12 the code is saved to EEPROM. I want to make some sort of basic UI on my LCD so that the code is also displayed there which does work, but the issue arises when trying to save the values to EEPROM as the data I am trying to store has two parts results.value
and HEX
. From what I have found it is not possible to store two values on EEPROM address so this would make getting the codes from EEPROM and transmitting them not possible using my method. Is there any way of doing this differently? Any helpful response would be greatly appreciated.
PS sorry if this question has been badly explained i find this topic very complex so please ask if you found something unclear.
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>
const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
IRsend irsend;
decode_results results;
LiquidCrystal_I2C lcd(0x27,20,4);
int potVal;
int currentCode;
int readCodeEEPROM;
void setup()
{
pinMode(13, INPUT_PULLUP); //button for clearing displayed code
pinMode(12, INPUT_PULLUP); //button for saving codes
pinMode(11, INPUT_PULLUP); //button for sending chosen code #
pinMode(10, INPUT_PULLUP); //button for recieving codes #
pinMode(8, INPUT_PULLUP); //button to clear selected eeprom
pinMode(9, OUTPUT); //IR led
pinMode(2, INPUT); //IR reciever
lcd.init();
lcd.backlight();
irrecv.enableIRIn();
Serial.begin(9600);
}
void loop()
{
potVal = analogRead(A1);
potVal = map(potVal, 0, 1023, 255, 0);
readCodeEEPROM = EEPROM.read(potVal);
lcd.setCursor(16, 0);
lcd.print(potVal);
if (irrecv.decode(&results) && digitalRead(10) == LOW) { //if ir codes recieved
lcd.setCursor(1, 1);
lcd.print("Code Recieved");
lcd.setCursor(1, 0);
lcd.print(results.value, HEX);
Serial.println(results.value, HEX);
}
if (digitalRead(12) == LOW) { //saving ir codes and hex
EEPROM.write(potVal, currentCode);
}
if (digitalRead(11) == LOW) { //sending ir codes
irsend.sendNEC(readCodeEEPROM, 32);
delay(30);
}
}