#include <Bounce2.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);
#define PIN_MODE INPUT_PULLUP
#define INTERVAL_IN_MS 10
Bounce2::Button b1 = Bounce2::Button();
Bounce2::Button b2 = Bounce2::Button();
int status = 0;
int position = 0;
unsigned long last = millis();
void setup() {
lcd.init();
lcd.backlight();
b1.attach ( 7, PIN_MODE );
b1.interval (INTERVAL_IN_MS);
b1.setPressedState ( LOW );
b2.attach ( 6, PIN_MODE );
b2.interval (INTERVAL_IN_MS);
b2.setPressedState ( LOW );
lcd.clear();
}
void loop() {
b1.update();
b2.update();
if (status == 0) // im Zustand 0
{
if (b2.pressed()) // Falls down gedrückt wurde
{
status = 1;
}
}
else if (status == 1)
{
if(millis()-last > 500)
{
position++;
last = millis();
}
if(position == 16)
{
status = 2;
}
if(b1.pressed())
{
status = 4;
}
}
else if (status == 3)
{
if(millis()-last > 500)
{
position--;
last = millis();
}
if(position == 0)
{
status = 0;
}
if (b2.pressed())
{
status = 4;
}
}
else if(status == 2)
{
if(b1.pressed())
{
status = 3;
}
}
else if(status == 4){
if(b1.pressed())
{
status = 3;
}
if(b2.pressed())
{
status = 1;
}
}
lcd.setCursor(0,0);
lcd.print(status);
lcd.setCursor(0,1);
lcd.print(position);
lcd.print(" ");
}