//#include <Wire.h>
#include <OneButtonTiny.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#include <Debouncer.h>
#include <InterpolationLib.h>
#define POTI_PIN A2
#define ECHO_PIN 3 //11
#define ENDSCH_PIN 5 //5
#define TAST_PIN 6 //6
#define RELAIS_PIN 7 //4
#define LED_ZUHAUSEPIN 8 //5
#define EEPROMSTART 10 //Erste Speicherstelle für Einstellwerte
#define SM_UNDEF 0
#define SM_ZUHAUSE 1
#define SM_ZUHAUSEGEPRUEFT 2
#define SM_VERLASSEN 3 //nicht mehr zu Hause, Relais noch aus
#define SM_UNTERWEGS 4 //Relais ein
#define SM_NACHHAUSE 5 //Endschalter, Relais aus
const int numValues = 10;
double xValues[10] = { 0, 100, 200, 300, 400, 600, 700, 800, 900, 1000 };
double yValues[10] = { 5, 10, 15, 20, 25, 30, 40, 50, 70, 100 };
const char VER1[17] = "Test Interp";
const char VER2[17] = "2025-05-26";
const char ZEILELEER[17] = " ";
boolean bLcdBacklight = true;
boolean bEndsch = false;
int iPotiVal;
int duration_ms = 50;
Debouncer debouncer(ENDSCH_PIN, duration_ms);
OneButtonTiny TastOB = OneButtonTiny(
TAST_PIN, // Input pin for the button
true, // Button is active LOW
true // Enable internal pull-up resistor
);
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode(POTI_PIN, INPUT);
pinMode(LED_ZUHAUSEPIN, OUTPUT); //Relais
pinMode(TAST_PIN, INPUT_PULLUP);
pinMode(ENDSCH_PIN, INPUT_PULLUP);
Serial.begin(9600);
lcd.init();
lcd.backlight();
delay(250);
lcd.noBacklight();
delay(1000);
lcd.backlight();
delay(500);
// Single Click event attachment
TastOB.attachClick(handleClickTast);
// Long Press Start event attachment
TastOB.attachLongPressStart(handleLongPressedTast);
// Double Click event attachment with lambda
TastOB.attachDoubleClick(handleDoubleClickTast);
delay(1000);
AnzeigeStart();
delay(2000);
Serial.println ("Anzeigestart Ende");
// lcd.noBacklight();
// bLcdBacklight = false;
}
void AnzeigeStart() {
Serial.println("Anzeigestart ");
// Serial.println(iAnzeigeMode);
char myDecString1[17];
char myDecString2[17];
sprintf(myDecString2, " ");
strcpy(myDecString2,ZEILELEER);
sprintf(myDecString1, VER1 );
sprintf(myDecString2, VER2 );
Anzeige(myDecString1,0);
Anzeige(myDecString2,1);
}
void loop() {
bool bTaster;
char myDecString1[17];
char myDecString2[17];
debouncer.update(); // you should update debouncer first
if (debouncer.edge()) { // if edge is detected
if (debouncer.rising()) // if edge is rising
bEndsch = false;
Serial.println("rise");
if (debouncer.falling()) // if edge is falling
bEndsch = true;
Serial.println("fall");
}
TastOB.tick();
bTaster = !digitalRead(TAST_PIN);
digitalWrite(LED_BUILTIN, bTaster);
iPotiVal = analogRead(POTI_PIN);
Serial.println(iPotiVal);
StandardAnzeige();
Serial.print(Interpolation::Linear(xValues, yValues, numValues, iPotiVal, false));
delay(500);
}
//============== Taster
static void handleClickTast() {
Serial.println("Clicked!");
int iVal;
//readEEPROM();
//return;
bLcdBacklight = !bLcdBacklight;
if (bLcdBacklight) lcd.backlight();
else lcd.noBacklight();
}
static void handleLongPressedTast() {
}
static void handleDoubleClickTast() { //Doppelklick: Einstellungen +- umschalten oder im Standard-Anzeige-Modus: Relais ein/ausschalten
Serial.println("Doubleclicked");
}
//============== Anzeige
void Anzeige(char caText[17], int iZeile){
lcd.setCursor(0, iZeile);
lcd.print(caText);
}
void StandardAnzeige() {
char myDecString1[17];
char myDecString2[17];
sprintf(myDecString2, " ");
strcpy(myDecString2,ZEILELEER);
sprintf(myDecString1, "Poti: %5d",iPotiVal );
Serial.println(myDecString1);
Anzeige(myDecString1,0);
Anzeige(myDecString2,1);
}
//============== LED