#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int lcdColumns = 16;
int lcdRows = 2;
int indicator=32;
int key2=25;
int count=0;
int battery=4;
int speed=2;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
void setup(){
Serial.begin(115200);
lcd.init();
lcd.backlight();
pinMode(indicator, INPUT);
pinMode(key2,INPUT);
pinMode(battery,INPUT);
pinMode(speed,INPUT);
lcdOff();
}
void loop(){
int keystate2=digitalRead(key2);
bool state1 = false;
if (keystate2==HIGH)
{
state1 = true;
if(state1)
count=count+1;
}
if(state1)
Serial.println(count);
if (count%2==0)
{
lcdOff();
}
else
{
lcdOn();
int state=digitalRead(indicator);
lcd.setCursor(0, 0);
if (state==HIGH)
{
lcd.print("LEFT SIDE ");
}
else
{
lcd.print("RIGHT SIDE");
}
int speedom=analogRead(speed);
int batteryval=analogRead(battery);
float vatval=(batteryval)*(5.0/4095);
float percentage=(vatval/5)*100;
float speedometer=(speedom)*(0.02442);
lcd.setCursor(0,1);
lcd.print(percentage,2);
lcd.setCursor(5,1);
lcd.print("%");
lcd.setCursor(8,1);
lcd.print(speedometer,1);
lcd.print("kmph");
}
}
void lcdOn() {
lcd.backlight();
}
void lcdOff() {
lcd.noBacklight();
lcd.clear();
}