#include <Wire.h>
#include<LiquidCrystal_I2C.h>
#define pot 15
#define sw 17
bool State = LOW;
bool SwState;
bool lastSwState = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long deBounceDelay = 50;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
Serial.begin(115200);
pinMode(sw, INPUT);
lcd.init();
//lcd.clear();
lcd.backlight();
}
void loop() {
int val = analogRead(pot);
int yee = map(val, 0, 4095, 0 ,100);
//Serial.println(yee);
lcd.setCursor(0, 0);
lcd.print("Value POT : ");
lcd.setCursor(12, 0);
lcd.print(yee);
int reading = digitalRead(sw);
if (reading != lastSwState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > deBounceDelay) {
if (reading != SwState) {
SwState = reading;
if (SwState == LOW) {
State = !State;
}
}
}
lastSwState = reading;
if (State == LOW) {
lcd.setCursor(0, 1);
lcd.print("OFF");
}
else {
lcd.setCursor(0, 1);
lcd.print(" ON");
}
}