#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Address 0x27, 16 columns and 2 rows
int selectPin = 2; // Select button
int upPin = 3; // Up button
int downPin = 4; // Down button
bool factoryResetSelected = false; // Flag to indicate if Factory Reset option is selected
void setup() {
pinMode(selectPin, INPUT_PULLUP);
pinMode(upPin, INPUT_PULLUP);
pinMode(downPin, INPUT_PULLUP);
lcd.init(); // Initialize LCD
lcd.backlight(); // Turn on backlight
showResetPrompt();
}
void loop() {
handleUserInput();
}
void handleUserInput() {
if (digitalRead(selectPin) == LOW) {
if (!factoryResetSelected) {
// Factory Reset option is selected
performFactoryReset();
} else {
// Back option is selected
goBack();
}
} else if (digitalRead(upPin) == LOW) {
// Up button pressed
factoryResetSelected = false;
updateSelection();
} else if (digitalRead(downPin) == LOW) {
// Down button pressed
factoryResetSelected = true;
updateSelection();
}
}
void showResetPrompt() {
lcd.setCursor(0, 0);
lcd.print(" Factory Reset?");
updateSelection();
}
void updateSelection() {
lcd.setCursor(0, 1);
if (!factoryResetSelected) {
lcd.print(">Yes No");
} else {
lcd.print(" Yes >No");
}
}
void performFactoryReset() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Resetting...");
// Perform Factory Reset here
}
void goBack() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Cancelled.");
delay(2000);
lcd.clear();
// Do whatever action needed to go back
}