#include <IRremote.h>
#include <LiquidCrystal.h>
bool programming_mode = false;
int group_num = 9;
int port_num = 8;
int delay_time = 1;
int firing_order = 1;
int key;
#define IR_RECEIVE_PIN 3 // Signal Pin of IR receiver
IRrecv receiver(IR_RECEIVE_PIN);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
const int numOptions = 3;
String options[numOptions] = {"Group Number: ", "Port Number: ", "Delay(ms): "};
String answers[numOptions];
void setup() {
Serial.begin(9600); // Initialize serial communication for debugging
while (!Serial);
Serial.println();
lcd.begin(20, 4);
//lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Programming Mode:");
lcd.println(firing_order);
for (int i = 0; i < numOptions; ++i) {
//delay(500);
//lcd.clear();
lcd.setCursor(0, i + 1);
lcd.print(options[i]);
while (true) {
if (Serial.available() > 0) {
answers[i] = Serial.readString();
Serial.print("Entered value: ");
Serial.println(answers[i]);
break;
}
//delay(100);
}
}
// Print stored answers for verification
//Serial.println("Stored Answers:");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Programming Mode:");
lcd.print(firing_order);
for (int i = 0; i < numOptions; ++i) {
lcd.setCursor(0, i + 1);
lcd.print(options[i]);
//lcd.print(": ");
lcd.println(answers[i]);
}
}
void loop() {
// Empty loop as setup() runs once
}
/*
void setup()
{
Serial.begin(115200);
lcd.begin(20, 4);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("!!! Firing Mode !!!");
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver
//digitalWrite(A1, HIGH);
}
void loop()
{
// Checks received an IR signal
if (IrReceiver.decode()) {
translateIR();
IrReceiver.resume(); // Receive the next value
}
}
void lcdPrint(char* text)
{
/*
lcd.setCursor(0, 1);
lcd.print(text);
Serial.println(text);
lcd.setCursor(0, 3);
lcd.print("IR code: ");
Serial.print("IR code: ");
lcd.print(IrReceiver.decodedIRData.command);
Serial.println(IrReceiver.decodedIRData.command);
Serial.println();
//
}
void translateIR()
{
// Takes command based on IR code received
switch (IrReceiver.decodedIRData.command) {
case 226: //MENU
programming_mode = !programming_mode;
if (programming_mode) {
Programming_Mode(key);
}
break;
case 162: // POWER
break;
case 34: // TEST
break;
case 176: // C
break;
case 2: // PLUS
break;
case 152: // MINUS
break;
case 194: // BACK
break;
case 224: // PREV
break;
case 168: // PLAY
break;
case 144: // NEXT
group_num = key;
firing_order ++;
break;
case 104: // 0
key = 0;
//Programming_Mode(key);
break;
case 48: // 1
key = 1;
break;
case 24: // 2
key = 2;
break;
case 122: // 3
key = 3;
break;
case 16: // 4
key = 4;
break;
case 56: // 5
key = 5;
break;
case 90: // 6
key = 6;
break;
case 66: // 7
key = 7;
break;
case 74: // 8
key = 8;
break;
case 82: // 9
key = 9;
break;
default:
lcd.clear();
lcd.print(IrReceiver.decodedIRData.command);
lcd.print(" other button");
}
Programming_Mode(key);
}
void Programming_Mode(int key_value) {
if (programming_mode) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Programming Mode: ");
lcd.setCursor(18, 0);
lcd.print(firing_order);
lcd.setCursor(0, 1);
lcd.print("Group Number: ");
lcd.setCursor(14, 1);
lcd.cursor();
lcd.blink();
lcd.print(key_value);
}
else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("!!! Firing Mode !!!");
}
}
*/