#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int addr= 0;
int led = 13;
int tambah, kurang, enter, menupos,
data, status,
submenu;
void setup()
{
// Serial.begin(115200);
pinMode(led, OUTPUT);
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
data = EEPROM.read(0);
lcd.init();
if(data == 1)
{
lcd.backlight();
}
else
{
lcd.noBacklight();
}
lcd.setCursor(3, 0);
lcd.print("~Welcome~");
lcd.setCursor(1, 1);
lcd.print("RaidenXRainsten");
delay(500);
lcd.clear();
}
void loop()
{
tambah = digitalRead(A0);
kurang = digitalRead(A1);
enter = digitalRead(A2);
data = EEPROM.read(0);
lcd.setCursor(0, 0);
lcd.print("Menu :");
// lcd.setCursor(0, 1);
// lcd.print("Light");
if(tambah != 1 && status == 0)
{
menupos = menupos + 1;
if(menupos > 2)
{
menupos = 0;
}
// lcd.clear();
}
if(kurang != 1 && status == 0)
{
menupos = menupos - 1;
if(menupos < 0)
{
menupos = 2;
}
// lcd.clear();
}
if(enter != 1 && status == 0)
{
submenu = menupos;
status = 1;
}
if(menupos == 0)
{
lcd.setCursor(0, 1);
lcd.print("Light ");
delay(100);
if(status == 1)
{
if(tambah != 1)
{
submenu = submenu + 1;
if(submenu > 1)
{
submenu = 0;
}
}
if(kurang != 1)
{
submenu = submenu - 1;
if(submenu < 0)
{
submenu = 1;
}
}
if(submenu == 0)
{
lcd.setCursor(12, 1);
lcd.print("> On");
if(enter != 1)
{
lcd.backlight();
EEPROM.write(0, 1);
}
}
if(submenu == 1)
{
lcd.setCursor(12, 1);
lcd.print(">Off");
if(enter != 1)
{
lcd.noBacklight();
EEPROM.write(0, 0);
}
}
}
}
if(menupos == 1)
{
lcd.setCursor(0, 1);
lcd.print("Reset ");
}
if(menupos == 2)
{
lcd.setCursor(0, 1);
lcd.print("Restart");
}
// Serial.println(menupos);
delay(200);
// if(tambah != 1)
// {
// data = data + 1;
// EEPROM.write(0,data);
// }
// if(kurang != 1)
// {
// data = data - 1;
// EEPROM.write(0,data);
// }
// delay(500);
// Serial.println(data);
}