#include <Bounce2.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
Bounce Mode =Bounce(5,50);
Bounce Select =Bounce(6,50);
int page=1;
int page2state=1;
//create an object called lcd, with address 0x38, wich is a display with 4 lines and 20 chars per line
LiquidCrystal_I2C lcd(0x20,16,2);
void setup()
{
pinMode(13,HIGH);
lcd.init();
lcd.setBacklight(HIGH);
lcd.setCursor(4,0);
lcd.print("Welcomes");
lcd.setCursor(3,1);
lcd.print("MPPT Solar");
delay(1000);
lcd.clear();
}
void loop()
{
digitalWrite(13,HIGH);
test();
SelectButton();
}
void test()
{
if(Mode.update()==true && Mode.read()==HIGH)
{
lcd.clear();
if(page==1);
{
page++;
}
if(page>3)
{
page=1;
}
}
switch(page)
{
case 1:
lcd.setCursor(0, 0);
lcd.print("Voltage:");
lcd.print("");
lcd.print("14.4");
lcd.print("V");
lcd.setCursor(0,1);
lcd.print("Amps:");
lcd.print("");
break;
case 2:
lcd.setCursor(0, 0);
lcd.print("Load 1");
lcd.setCursor(1,1);
lcd.print("ON");
lcd.setCursor(5,1);
lcd.print("OFF");
break;
case 3:
lcd.setCursor(0, 0);
lcd.print("page3");
break;
}
}
void SelectButton()
{
if(Select.update()==true && Select.read()==HIGH)
{
lcd.clear();
if(page2state==1)
{
page2state=0;
lcd.setCursor(0, 0);
lcd.print("Load 1 ");
lcd.setCursor(4,1);
lcd.print(">OFF");
lcd.setCursor(1,1);
lcd.print("ON");
}
else if(page2state==0)
{
page2state=1;
lcd.setCursor(0, 0);
lcd.print("page2");
lcd.setCursor(0,1);
lcd.print(">ON");
lcd.setCursor(5,1);
lcd.print("OFF");
}
}
}
没有评论:
发表评论