#define sw1 34
#define sw2 13
int count,keep;
bool on = true;
bool off = false;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(sw1, INPUT_PULLUP);
pinMode(sw2, INPUT_PULLUP);
lcd.init();
Serial.begin(9600);
}
void loop() {
int Power = digitalRead(sw1);
int OK = digitalRead(sw2);
if (on == true) {
if (Power == 0) {
delay(100);
count++;
if (count == 20) {
ON();
}
}
else {
count = 0;
}
}
if (off == true) {
if (Power == 0) {
delay(100);
count++;
keep = count;
if (count == 20) {
OFF();
}
}
else {
count = 0;
}
if (OK == 0 && keep >= 20) {
lcd.clear();
lcd.noBacklight();
off = false;
on = true;
keep = 0;
}
}
Serial.print("keep = ");
Serial.print(keep);
Serial.print(" : count = ");
Serial.print(count);
Serial.print(" : Power = ");
Serial.println(Power);
}
void ON() {
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(" Welcome");
lcd.setCursor(0, 1);
lcd.print(" Now_Trun_ON");
on = false;
off = true;
}
void OFF() {
lcd.setCursor(0, 0);
lcd.print(" Trun_Off ??");
lcd.setCursor(0, 1);
lcd.print(" >>>Yes ");
}