#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Pindefinitionen für das Display
const int RS= 8;
const int EN= 9;
const int DB7= 7;
const int DB6= 6;
const int DB5= 5;
const int DB4= 4;
const int LED= 10;
// Pin für die Temperatursensoren
const int One_Wire_Bus = 3;
// Pins für die Relais
const int VentilRelaisPin =12;
const int PumpeRelaisPin =13;
// Variablen für Auswertung der Tasten
const int dec=-1;
const int inc=1;
const int Tasterrechts= inc;
const int Tasteroben= 1;
const int Tasterunten= 2;
const int Tasterlinks= dec;
const int Tasterselect= 4;
const int KeinTaster= 5;
// --Displayzustände--
// Definition der Zustände
const byte Z_Statusanzeige = 0;
const byte Z_SetPoolSoll = 1;
const byte Z_SetHystereseEin = 2;
const byte Z_SetHystereseAus = 3;
// Zustandsvaiable
byte Display = Z_Statusanzeige;
// --Betriebszustände--
// Definition der Zustände
const byte Z_Aus=0;
const byte Z_Umwaelzen=1;
const byte Z_Solarbetrieb=2;
const byte Z_SolarbetriebEin=3;
const byte Z_SolarbetriebAus=4;
const byte Z_Init=99;
// Zustandsvaiablen
byte PumpeVentil=Z_Init; //Initialisierung von Ventilstand
// Werte für bestimmte Zeichen im Display
const unsigned char Pfeillinks=127,Pfeilrechts=126,CharGrad=223;
// --Variablen für die Temperaturen--
// Sensortemperaturen
float PoolIst=0, SolarIst=0;
// SOLL, SOLLMAX und SOLLMIN-Werte für die Pooltemperatur
float PoolSoll=29.5, PoolSollMax=32 , PoolSollMin=20;
// Ein- bzw. Ausschalthysterese für Solarbetrieb
int HystereseEin=6, HystereseEinMin=0, HystereseEinMax=9;
int HystereseAus=2, HystereseAusMin=0, HystereseAusMax=8;
// Einige Merker
bool zustandwechsel=false, wertwechsel=false, TempAenderung=false;
const bool ein=true, aus=false;
// --Variablen für die Timer--
const byte stop=0, start=1, laeuft=2;
// Displaytimer
const int DisplayTimeoutZeit = 5 *1000; // nach X Sekunden (*Millisekunden) ohne Tastendruck soll das Display wieder auf Statusanzeige schalten
bool DisplayTimeout=false;
byte DisplayTimer=stop;
// Solarsteuerung
const int SolarEinWartezeit= 10000, SolarAusWartezeit= 10000; // X Minuten*Millisekunden
bool SolarEinTimeout=false, SolarAusTimeout=false;
byte SolarEinTimer=stop, SolarAusTimer=stop;
// Fahrzeit des 3-Wege-Ventils
const unsigned long VentilStellZeit=6*1000; // X Sekunden (*Millisekunden)
bool VentilTimeout=false;
byte VentilTimer=stop;
// Ablesung Temperaturwerte
unsigned int AbleseFrequenz=3*1000;
// Erzeugen der Objekte für Display und Temperatursensoren
LiquidCrystal lcd(RS, EN, DB4, DB5, DB6, DB7);
OneWire oneWire(One_Wire_Bus);
DallasTemperature Ds18b20(&oneWire);
void HoleTemperaturen(void);
int Holetaster(void);
void SteuerungDisplay(int Taster);
void SteuerungPumpeVentil(void);
void UpdateTimer(void);
//void Statusanzeige(void);
//void SetPoolSoll(int incdec);
//void TimerDisplay(void);
//void TimerSolarEin(void);
//void TimerSolarAus(void);
//void TimerVentil(void);
//void SetHystereseEin(int incdec);
//void SetHystereseAus(int incdec);
// Prüft ob min<=wert>=max
bool imBereich(float wert, float min, float max){
if((wert-min)*(wert-max) <= 0) return true;
return false;
}
void setup() { // Funktionsaufruf "ds18b20list();" muss im Setup eingebunden werden
Serial.begin(115200); //seriellen Monitor aktivieren
Serial.println(F("Start..."));
Ds18b20.begin();
Ds18b20.setWaitForConversion(false);
Ds18b20.requestTemperatures();
//server.on("/lots", handleListDevice);
}
void loop() {
//const byte anzahl = sizeof(sensor) / 8 ;
if (Ds18b20.getDS18Count()==2) {
String temp = "[";
temp += (String)"{\"name\":\"" + "Pool" + "\",\"wert\":\"" + Ds18b20.getTempCByIndex(0) + "\"},";
temp += (String)"{\"name\":\"" + "Solar" + "\",\"wert\":\"" + Ds18b20.getTempCByIndex(1) + "\"}";
temp += "]";
//server.send(200, "application/json", temp);
Serial.println(temp);
delay(2000);
}
else {
String temp;
Serial.println("Die Anzahl der Sensoren stimmt nicht überein.");
temp= "[{\"name\":\"Fehler Anzahl DS18b20\",\"wert\":\"\"}]";
Serial.println(temp);
}
Ds18b20.requestTemperatures();
}