#include <LiquidCrystal_I2C.h>
#include <Bounce2.h>
#include <Ticker.h>
#include <EEPROM.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
Bounce b1 = Bounce();
Bounce b2 = Bounce();
int temp = 150;
int prevTime;
int prevWert;
bool firstTime;
int counter1 = 0;
int counter2 = 0;
int counter3 = 0;
int plus = 1;
int minus = 1;
bool isPressed = false;
void anzeigen(int temp)
{
lcd.clear();
lcd.setCursor(3,0);
lcd.print(temp);
lcd.print(" grad");
}
void tempEinstellen ()
{
if(!b1.read())
{
isPressed = true;
if(counter1 > 5)
{
plus = 5;
}
else
{
plus = 1;
}
temp = temp + plus;
counter1++;
firstTime = true;
}
else if(!b2.read())
{
isPressed = true;
if(counter2 > 5)
{
minus = 5;
}
else
{
minus = 1;
}
temp = temp - minus;
counter2++;
firstTime = true;
}
else
{
isPressed = false;
counter1 = 0;
counter2 = 0;
}
if(temp >=450)
{
temp = 450;
}
if(temp <= 150)
{
temp = 150;
}
if(!isPressed && firstTime)
{
if(counter3 >=5)
{
lcd.clear();
byte temp1er = temp % 10;
byte temp10er = temp/10;
EEPROM.write(0,temp1er);
EEPROM.write(1,temp10er);
}
if(counter3 >= 6)
{
anzeigen(temp);
}
if(counter3 >= 7 )
{
lcd.clear();
}
if(counter3 >= 8)
{
anzeigen(temp);
firstTime = false;
counter3 = 0;
}
counter3++;
}
}
Ticker t1(tempEinstellen,200);
void setup()
{
Serial.begin(9600);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
b1.attach(2, INPUT_PULLUP);
b2.attach(3, INPUT_PULLUP);
b1.interval(10);
b2.interval(10);
t1.start();
temp = EEPROM.read(0)+EEPROM.read(1)*10;
}
void loop()
{
t1.update();
b1.update();
b2.update();
if(temp != prevWert)
{
anzeigen(temp);
}
prevWert = temp;
}