#include <PID_v1.h>
#include <ESP32Servo.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <INA226_WE.h>
#include <I2C_RTC.h>
#include "Adafruit_FRAM_I2C.h"
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ST7796S_kbv.h"
/* //Functions to update */
TaskHandle_t TFT_loop_Handle = NULL;
void TFT_loop(void *pvParameters );
TaskHandle_t Sensors_loop_Handle = NULL;
void Sensors_loop(void *pvParameters );
TaskHandle_t IO_loop_Handle = NULL;
void IO_loop(void *pvParameters );
TaskHandle_t Counter_loop_Handle = NULL;
void Counter_loop(void *pvParameters );
TaskHandle_t FRAM_updater_Handle = NULL;
void FRAM_updater(void *pvParameters );
TaskHandle_t Serial_updater_Handle = NULL;
void Serial_updater(void *pvParameters );
unsigned long lastSensorsUpdate = 0;
unsigned long lastIOloopUpdate = 0;
unsigned long lastCounterLoopUpdate = 0;
static PCF8563 RTC;
#define TFT_RST 4
#define TFT_DC 2
#define TFT_CS 5
Adafruit_ST7796S_kbv tft = Adafruit_ST7796S_kbv(TFT_CS, TFT_DC, TFT_RST);
INA226_WE ina226_Out_12vdc = INA226_WE(0x40);
INA226_WE ina226_Servo = INA226_WE(0x44);
INA226_WE ina226_Arduino = INA226_WE(0x41);
int MENU_FORWARD_BUTTON_PIN = 34;
int MENU_BACK_BUTTON_PIN = 35;
#define Stop_Pump_Servo_PIN 33 //input
#define Braender_Flamme_PIN 32 // input
#define Blaeser_PIN 25 //pwm output
#define SERVO_PIN 26 //pwm output
#define CircPump_PIN 27 // output
#define Braender_PIN 12 // output
#define ONE_WIRE_BUS 13 // data
#define Stop_Servo_Tid_Pin 14 // output
#define Kedel_Hys 3.5 //-------------------------------------------------Hysterise Kedel
#define CircPump_Set 16 //----------------------------------------------CircPump Setpoint
#define CircPump_Hys 1 //-----------------------------------------------Hysteresis CircPump
int currentPage = 1; //variable to keep track of the current menu page
double FlowF_Set = 55; //-----------------------------------------------Will be overwritten later in map fuction
double FlowF_Temp, output;
double Kp = 3.4; //-----------------------------------------------------Proportional gain
double Ki = 3.0; //-----------------------------------------------------Integral gain
double Kd = 0.75; //-----------------------------------------------------Derivative gain
PID myPID(&FlowF_Temp, &output, &FlowF_Set, Kp, Ki, Kd, DIRECT);
bool SyncUpdatePID_Flag = false;
bool SyncUpdatePID_LatestUpdate = false;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
Servo servo;
ESP32PWM pwm_Blaeser_PIN;
int freq = 1000;
float Kedel_Temp;
float Out_Temp_Sensor1, Out_Temp_Sensor2;
float average; //---------------Variable to store average temperature OutTemp_Sensor1, OutTemp_Sensor2--//
float Box_Temp;
float FlowR_Temp;
float Cwater_Temp;
float Wwater_Temp;
float Chimney_Temp;
//Sensor data received and ready to take decitions
bool SensorsReady = false;
//Outdoor temperure smooth
bool SmoothFirstRun = true;
//------------------------------Variables operating counter(Braender_Flamme / CircPump)--------------------//
bool lastState_Braender_Flamme = false;
bool lastState_CircPump = false;
unsigned int timeBufferTimer_Braender_Flamme = 0;
unsigned int timeBufferTimer_CircPump = 0;
byte timeBufferMinutter_Braender_Flamme = 0;
byte timeBufferMinutter_CircPump = 0;
byte timeBufferSekunder_Braender_Flamme = 0;
byte timeBufferSekunder_CircPump = 0;
unsigned long timerStart_Braender_Flamme = 0;
unsigned long timerStart_CircPump= 0;
unsigned int CounterTurnOnTimes_Braender_Flamme = 0;
unsigned int CounterTurnOnTimes_CircPump = 0;
//----------------------------------------------------------------------------------------------------//
//------------------------------Printer operating counter---------------------------------------------//
unsigned long lastPrintUpdate = 0;
unsigned long IntervalPrintUpdate = 2000;//Print besked hver 2s
unsigned long IntervalPlotterUpdate = 100;//Print besked hver 2s
//----------------------------------------------------------------------------------------------------//
//------------------------------Screen automatic updater---------------------------------------------//
unsigned long lastScreenUpdate = 0;
unsigned long IntervalScreenUpdate = 1000;//Print besked hver 1s
//----------------------------------------------------------------------------------------------------//
//------------------------------Variables to CircPump if it has been stopped to long-----------------//
long lastTimeBeginOn = 0;
long lastTimeBeginOff = 0;
long lastTimeFinishedInterval = 0;
bool CirPumpOldState = 0;
long TimeToBeOn = 900000;//----Time the CircPump will be running if it has been stopped for too long (10m=600000 millis)
long MaxTimeOff = 43200000;//---Max time the pump can be stopped before turning on the CircPump (12t=43200000 millis)
//---------------------------------------------------------------------------------------------------//
//---------------------------Timer for servo power pin-----------------------------//
unsigned long Stop_Servo_Tid_PowerREQ = 0;//Last time the servo was asked to turn on in edge pos
unsigned long Stop_Servo_Tid_PowerREQ_OnTime = 5000;//When turned on in edge position stay on for this time
double Stop_Servo_Tid_PowerREQ_servoPos = 0;//The position in percentage last time the servo was turned on
double Stop_Servo_Tid_Hys = 1.0;//How many degree the PID need to change setpoint before the servo will repower
//---------------------------------------------------------------------------------//
//For FRAM
Adafruit_FRAM_I2C fram = Adafruit_FRAM_I2C();
bool FRAM_OK = false;
long lastFRAMwrite = 0;
//Global vars
float Out_12vdc_V = 0.0;
float Out_12vdc_mA = 0.0;
float Servo_V = 0.0;
float Servo_mA = 0.0;
float Arduino_V = 0.0;
float Arduino_mA = 0.0;
float average_Out_Temp = 0.0;
float Blaeser_Output = 0.0;
float Kedel_Set = 0.0;
float output_Percentage = 0.0;
float Blaeser_Output_Procent = 0.0;
bool Braender_pin_cache_old = false;
//Application cycle time monitor
unsigned long Time_Start = 0;
unsigned long Time_TFT_loop = 0;
unsigned long Time_Sensors_loop = 0;
unsigned long Time_IO_loop = 0;
unsigned long Time_Counter_loop = 0;
unsigned long Time_FRAM_updater = 0;
unsigned long Time_Serial_updater = 0;
unsigned int Time_TFT_loop_LAST = 0;
unsigned int Time_Sensors_loop_LAST = 0;
unsigned int Time_IO_loop_LAST = 0;
unsigned int Time_Counter_loop_LAST = 0;
unsigned int Time_FRAM_updater_LAST = 0;
unsigned int Time_Serial_updater_LAST = 0;
unsigned int CycleTime_SUM_RUNS = 0;
unsigned long Time_TFT_loop_SUM = 0;
unsigned long Time_Sensors_loop_SUM = 0;
unsigned long Time_IO_loop_SUM = 0;
unsigned long Time_Counter_loop_SUM = 0;
unsigned long Time_FRAM_updater_SUM = 0;
unsigned long Time_Serial_updater_SUM = 0;
unsigned long Time_TFT_loop_AVG = 0;
unsigned long Time_Sensors_loop_AVG = 0;
unsigned long Time_IO_loop_AVG = 0;
unsigned long Time_Counter_loop_AVG = 0;
unsigned long Time_FRAM_updater_AVG = 0;
unsigned long Time_Serial_updater_AVG = 0;
bool DebugMode = true;
bool PlotterMode = false;
String SerielInputBuffer = "";
int SerielInputBuffer_index = 0;
bool ParameterReception = false;
float fmap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
size_t printDebug(String x)
{
if(DebugMode){
return Serial.print(x);
}else{
return 0;
}
}
size_t printDebug(int x)
{
if(DebugMode){
return Serial.print(x);
}else{
return 0;
}
}
size_t printDebug(float x)
{
if(DebugMode){
return Serial.print(x);
}else{
return 0;
}
}
size_t printDebug(double x)
{
if(DebugMode){
return Serial.print(x);
}else{
return 0;
}
}
size_t printDebug(long x)
{
if(DebugMode){
return Serial.print(x);
}else{
return 0;
}
}
size_t printDebug(unsigned long x)
{
if(DebugMode){
return Serial.print(x);
}else{
return 0;
}
}
size_t printDebug(unsigned int x)
{
if(DebugMode){
return Serial.print(x);
}else{
return 0;
}
}
size_t printDebugln(String x)
{
if(DebugMode){
return Serial.println(x);
}else{
return 0;
}
}
size_t printDebugln(int x)
{
if(DebugMode){
return Serial.println(x);
}else{
return 0;
}
}
size_t printDebugln(float x)
{
if(DebugMode){
return Serial.println(x);
}else{
return 0;
}
}
size_t printDebugln(double x)
{
if(DebugMode){
return Serial.println(x);
}else{
return 0;
}
}
size_t printDebugln(long x)
{
if(DebugMode){
return Serial.println(x);
}else{
return 0;
}
}
size_t printDebugln(unsigned long x)
{
if(DebugMode){
return Serial.println(x);
}else{
return 0;
}
}
size_t printDebugln(unsigned int x)
{
if(DebugMode){
return Serial.println(x);
}else{
return 0;
}
}
void FRAM_reset_only_CircPump_Time(){
//---timeBufferTimer_Braender_Flamme
//fram.write(0, 0);
//fram.write(1, 0);
//---timeBufferTimer_CircPump
fram.write(2, 0);
fram.write(3, 0);
//---timeBufferMinutter_Braender_Flamme
//fram.write(4, 0);
//---timeBufferMinutter_CircPump
fram.write(5, 0);
//---timeBufferSekunder_Braender_Flamme
//fram.write(6, 0);
//---timeBufferSekunder_CircPump
fram.write(7, 0);
//---CounterTurnOnTimes_Braender_Flamme
//fram.write(8, 0);
//fram.write(9, 0);
//---CounterTurnOnTimes_CircPump
//fram.write(10, 0);
//fram.write(11, 0);
}
void FRAM_reset_only_CircPump_Counter(){
//---timeBufferTimer_Braender_Flamme
//fram.write(0, 0);
//fram.write(1, 0);
//---timeBufferTimer_CircPump
//fram.write(2, 0);
//fram.write(3, 0);
//---timeBufferMinutter_Braender_Flamme
//fram.write(4, 0);
//---timeBufferMinutter_CircPump
//fram.write(5, 0);
//---timeBufferSekunder_Braender_Flamme
//fram.write(6, 0);
//---timeBufferSekunder_CircPump
//fram.write(7, 0);
//---CounterTurnOnTimes_Braender_Flamme
//fram.write(8, 0);
//fram.write(9, 0);
//---CounterTurnOnTimes_CircPump
fram.write(10, 0);
fram.write(11, 0);
}
void FRAM_reset_Kun_Braender_Tid(){
//---timeBufferTimer_Braender_Flamme
fram.write(0, 0);
fram.write(1, 0);
//---timeBufferTimer_CircPump
//fram.write(2, 0);
//fram.write(3, 0);
//---timeBufferMinutter_Braender_Flamme
fram.write(4, 0);
//---timeBufferMinutter_CircPump
//fram.write(5, 0);
//---timeBufferSekunder_Braender_Flamme
fram.write(6, 0);
//---timeBufferSekunder_CircPump
//fram.write(7, 0);
//---CounterTurnOnTimes_Braender_Flamme
//fram.write(8, 0);
//fram.write(9, 0);
//---CounterTurnOnTimes_CircPump
//fram.write(10, 0);
//fram.write(11, 0);
}
void FRAM_reset_Kun_Braender_Taeller(){
//---timeBufferTimer_Braender_Flamme
//fram.write(0, 0);
//fram.write(1, 0);
//---timeBufferTimer_CircPump
//fram.write(2, 0);
//fram.write(3, 0);
//---timeBufferMinutter_Braender_Flamme
//fram.write(4, 0);
//---timeBufferMinutter_CircPump
//fram.write(5, 0);
//---timeBufferSekunder_Braender_Flamme
//fram.write(6, 0);
//---timeBufferSekunder_CircPump
//fram.write(7, 0);
//---CounterTurnOnTimes_Braender_Flamme
fram.write(8, 0);
fram.write(9, 0);
//---CounterTurnOnTimes_CircPump
//fram.write(10, 0);
//fram.write(11, 0);
}
DeviceAddress Kedel_Temp_Adr = {0x28, 0x61, 0x64, 0x34, 0x89, 0x59, 0xFD, 0x02};
DeviceAddress FlowF_Temp_addr = {0x28, 0x61, 0x64, 0x34, 0x89, 0x63, 0x3A, 0x81};
DeviceAddress FlowR_Temp_addr = {0x28, 0x26, 0xF4, 0x36, 0x00, 0x00, 0x00, 0xE2};
DeviceAddress Cwater_Temp_addr = {0x28, 0x52, 0x53, 0x37, 0x00, 0x00, 0x00, 0x4B};
DeviceAddress Wwater_Temp_addr = {0x28, 0x2F, 0x9C, 0x35, 0x00, 0x00, 0x00, 0xD3};
DeviceAddress Out_Temp_Sensor1_addr = {0x28, 0x33, 0x24, 0x34, 0x00, 0x00, 0x00, 0x0B};
DeviceAddress Out_Temp_Sensor2_addr = {0x28, 0xB2, 0xDE, 0x37, 0x00, 0x00, 0x00, 0x45};
DeviceAddress Box_Temp_addr = {0x28, 0x1C, 0xAF, 0x36, 0x00, 0x00, 0x00, 0x25};
DeviceAddress Chimney_Temp_addr = {0x28, 0xCB, 0x94, 0x38, 0x00, 0x00, 0x00, 0x85};
void setup() {
Serial.begin(115200);
Wire.begin();
while (!Serial);
RTC.begin();
tft.begin();
tft.setRotation(3);
tft.fillScreen(0);
pinMode(Blaeser_PIN, OUTPUT);
pinMode(Stop_Pump_Servo_PIN, INPUT);
pinMode(CircPump_PIN, OUTPUT);
pinMode(Braender_Flamme_PIN, INPUT);
pinMode(Braender_PIN, OUTPUT);
pinMode(MENU_FORWARD_BUTTON_PIN, INPUT);
pinMode(MENU_BACK_BUTTON_PIN, INPUT);
ina226_Out_12vdc.init();
ina226_Servo.init();
ina226_Arduino.init();
ina226_Out_12vdc.setResistorRange(0.010,6.0); //-----------------(0).(choose shunt resistor).(Max current)
ina226_Servo.setResistorRange(0.010,6.0); //---------------------(0).(choose shunt resistor).(Max current)
ina226_Arduino.setResistorRange(0.010,6.0); //-------------------(0).(choose shunt resistor).(Max current)
ina226_Out_12vdc.setCorrectionFactor(1.00);//---------------------Offset for INA226(only current)
ina226_Servo.setCorrectionFactor(1.00);//-------------------------Offset for INA226(only current)
ina226_Arduino.setCorrectionFactor(1.00);//-----------------------Offset for INA226(only current)
ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
ESP32PWM::allocateTimer(3);
/*servo.setPeriodHertz(50);
servo.attach(SERVO_PIN, 500, 2400);
*/
pwm_Blaeser_PIN.attachPin(Blaeser_PIN, freq, 10); // 8 bits(0-255)
servo.attach(SERVO_PIN);
myPID.SetMode(AUTOMATIC);
myPID.SetOutputLimits(0, 130); //-------------------------------------------Max/Min output Shunt_Set(Servo) remenber to set line 95 too
sensors.begin();
//INIT FRAM
if (fram.begin()) { // you can stick the new i2c addr in here, e.g. begin(0x51);
printDebugln("Found I2C FRAM");
FRAM_OK = true;
} else {
printDebugln("I2C FRAM not identified ... check your connections?\r\n");
}
//RESET FRAM DATA TO ZERO:
//FRAM_reset_only_CircPump_Time();//Kommenter denne linje ud, hvis timetællerne circ ikke skal slettes!
//FRAM_reset_only_CircPump_Counter();
//FRAM_reset_Kun_Braender_Tid();//Kommenter denne linje ud, hvis Braender timetællerne ikke skal slettes!
//FRAM_reset_Kun_Braender_Taeller();
if(FRAM_OK){
//Move data from FRAM to variables
/*VARIABLE : FRAM address
unsigned int timeBufferTimer_Braender_Flamme : 0-1 (2 bytes)
unsigned int timeBufferTimer_CircPump : 2-3 (2 bytes)
byte timeBufferMinutter_Braender_Flamme : 4
byte timeBufferMinutter_CircPump : 5
byte timeBufferSekunder_Braender_Flamme : 6
byte timeBufferSekunder_CircPump : 7
unsigned int CounterTurnOnTimes_Braender_Flamme: 8-9 (2 bytes)
unsigned int CounterTurnOnTimes_CircPump = 0: 10-11 (2 bytes)
*/
//---timeBufferTimer_Braender_Flamme
uint8_t byteArray_timeBufferTimer_Braender_Flamme[2];
byteArray_timeBufferTimer_Braender_Flamme[0] = fram.read(0);
byteArray_timeBufferTimer_Braender_Flamme[1] = fram.read(1);
timeBufferTimer_Braender_Flamme |= (uint32_t)byteArray_timeBufferTimer_Braender_Flamme[0];
timeBufferTimer_Braender_Flamme |= (uint32_t)byteArray_timeBufferTimer_Braender_Flamme[1] << 8;
//---timeBufferTimer_CircPump
uint8_t byteArray_timeBufferTimer_CircPump[2];
byteArray_timeBufferTimer_CircPump[0] = fram.read(2);
byteArray_timeBufferTimer_CircPump[1] = fram.read(3);
timeBufferTimer_CircPump |= (uint32_t)byteArray_timeBufferTimer_CircPump[0];
timeBufferTimer_CircPump |= (uint32_t)byteArray_timeBufferTimer_CircPump[1] << 8;
//---timeBufferMinutter_Braender_Flamme
timeBufferMinutter_Braender_Flamme = fram.read(4);
//---timeBufferMinutter_CircPump
timeBufferMinutter_CircPump = fram.read(5);
//---timeBufferSekunder_Braender_Flamme
timeBufferSekunder_Braender_Flamme = fram.read(6);
//---timeBufferSekunder_CircPump
timeBufferSekunder_CircPump = fram.read(7);
//---CounterTurnOnTimes_Braender_Flamme
uint8_t byteArray_CounterTurnOnTimes_Braender_Flamme[2];
byteArray_CounterTurnOnTimes_Braender_Flamme[0] = fram.read(8);
byteArray_CounterTurnOnTimes_Braender_Flamme[1] = fram.read(9);
CounterTurnOnTimes_Braender_Flamme |= (uint32_t)byteArray_CounterTurnOnTimes_Braender_Flamme[0];
CounterTurnOnTimes_Braender_Flamme |= (uint32_t)byteArray_CounterTurnOnTimes_Braender_Flamme[1] << 8;
//---CounterTurnOnTimes_CircPump
uint8_t byteArray_CounterTurnOnTimes_CircPump[2];
byteArray_CounterTurnOnTimes_CircPump[0] = fram.read(10);
byteArray_CounterTurnOnTimes_CircPump[1] = fram.read(11);
CounterTurnOnTimes_CircPump |= (uint32_t)byteArray_CounterTurnOnTimes_CircPump[0];
CounterTurnOnTimes_CircPump |= (uint32_t)byteArray_CounterTurnOnTimes_CircPump[1] << 8;
}
//Initiate DS18B20 sensors
sensors.setResolution(Kedel_Temp_Adr , 12);
sensors.setResolution(FlowF_Temp_addr , 12);
sensors.setResolution(FlowR_Temp_addr , 12);
sensors.setResolution(Cwater_Temp_addr , 12);
sensors.setResolution(Wwater_Temp_addr , 12);
sensors.setResolution(Out_Temp_Sensor1_addr , 12);
sensors.setResolution(Out_Temp_Sensor2_addr , 12);
sensors.setResolution(Box_Temp_addr , 12);
sensors.setResolution(Chimney_Temp_addr , 12);
// Run task indepentdently
printDebugln("Initiere TFT_loop");
xTaskCreatePinnedToCore(
TFT_loop
, "TFT_loop" // A name just for humans
, 5024 // This stack size can be checked and adjusted by reading the Stack Highwater
, NULL
, 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, &TFT_loop_Handle
, 1 );
delay(200);
printDebugln("Initiere Sensors_loop");
xTaskCreatePinnedToCore(
Sensors_loop
, "Sensors_loop" // A name just for humans
, 5024 // This stack size can be checked and adjusted by reading the Stack Highwater
, NULL
, 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, &Sensors_loop_Handle
, 1 );
delay(200);
printDebugln("Initiere IO_loop");
xTaskCreatePinnedToCore(
IO_loop
, "IO_loop" // A name just for humans
, 5024 // This stack size can be checked and adjusted by reading the Stack Highwater
, NULL
, 3 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, &IO_loop_Handle
, 1 );
delay(200);
printDebugln("Initiere Counter_loop");
xTaskCreatePinnedToCore(
Counter_loop
, "Counter_loop" // A name just for humans
, 5024 // This stack size can be checked and adjusted by reading the Stack Highwater
, NULL
, 2 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, &Counter_loop_Handle
, 1 );
delay(200);
printDebugln("Initiere FRAM_updater");
xTaskCreatePinnedToCore(
FRAM_updater
, "FRAM_updater" // A name just for humans
, 5024 // This stack size can be checked and adjusted by reading the Stack Highwater
, NULL
, 1 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, &FRAM_updater_Handle
, 1 );
delay(200);
printDebugln("Initiere Serial_updater");
xTaskCreatePinnedToCore(
Serial_updater
, "Serial_updater" // A name just for humans
, 5024 // This stack size can be checked and adjusted by reading the Stack Highwater
, NULL
, 1 // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest.
, &Serial_updater_Handle
, 1 );
delay(200);
}
char dateString[] = "xx-xx-xxxx xx:xx:xx";//Alle x bliver erstattet senere.
//---------Topline all page---------
float pageFloatBuffer_0 = 0;
//----------------------------------
//----------Buffer page 1-----------
float pageFloatBuffer_1 = 0;
float pageFloatBuffer_2 = 0;
float pageFloatBuffer_3 = 0;
float pageFloatBuffer_4 = 0;
float pageFloatBuffer_5 = 0;
float pageFloatBuffer_6 = 0;
//---------------------------------
//----------Buffer page 2----------
unsigned int pageUIntBuffer_7 = 0;
byte pageByteBuffer_8 = 0;
byte pageByteBuffer_9 = 0;
float pageFloatBuffer_10 = 0;
unsigned int pageUIntBuffer_11 = 0;
byte pageByteBuffer_12 = 0;
byte pageByteBuffer_13 = 0;
float pageFloatBuffer_14 = 0;
//--------------------------------
//----------Buffer page 3---------
float pageFloatBuffer_15 = 0;
float pageFloatBuffer_16 = 0;
float pageFloatBuffer_17 = 0;
float pageFloatBuffer_18 = 0;
//--------------------------------
//----------Buffer page 4---------
float pageFloatBuffer_19 = 0;
float pageFloatBuffer_20 = 0;
float pageFloatBuffer_21 = 0;
float pageFloatBuffer_22 = 0;
float pageFloatBuffer_23 = 0;
//-------------------------------
//----------Buffer page 5--------
float pageFloatBuffer_24 = 0;
float pageFloatBuffer_25 = 0;
float pageFloatBuffer_26 = 0;
float pageFloatBuffer_27 = 0;
float pageFloatBuffer_28 = 0;
//-------------------------------
//----------Buffer page 6--------
float pageFloatBuffer_29 = 0;
float pageFloatBuffer_30 = 0;
//-------------------------------
//----------Buffer page 7--------
float pageFloatBuffer_31 = 0;
float pageFloatBuffer_32 = 0;
float pageFloatBuffer_33 = 0;
float pageFloatBuffer_34 = 0;
float pageFloatBuffer_35 = 0;
float pageFloatBuffer_36 = 0;
//-------------------------------
/*//---------Buffer page 8---------
float pageFloatBuffer_37 = 0;
float pageFloatBuffer_38 = 0;
float pageFloatBuffer_39 = 0;
float pageFloatBuffer_40 = 0;
float pageFloatBuffer_41 = 0;
float pageFloatBuffer_42 = 0;
//-------------------------------*/
void updatePage(){
//---------- Top line on all page--------
tft.setCursor(245, 0);
tft.setTextSize(2);
//tft.print("4-12-2024 11:42:10");
//Slet gammelt print ved at skrive gammel tekst med baggrundsfarve
tft.setTextColor(0x0000);
tft.print(dateString);//tft.print("4-12-2024 11:42:10");
char bufferString[6];
int time_buffer = RTC.getDay();
itoa(time_buffer, bufferString, 10);//itoa(heltal som skal konverteres, String buffer, 10 tals systemet);
if(time_buffer < 10){
dateString[0] = '0'; // 0x-xx-xxxx xx:xx:xx
dateString[1] = bufferString[0]; // xN-xx-xxxx xx:xx:xx
}else{
dateString[0] = bufferString[0]; // Nx-xx-xxxx xx:xx:xx
dateString[1] = bufferString[1]; // xN-xx-xxxx xx:xx:xx
}
//dateString[2] = '-';//Allerede gjort ved initiering
time_buffer = RTC.getMonth();
itoa(time_buffer, bufferString, 10);//itoa(heltal som skal konverteres, String buffer, 10 tals systemet);
if(time_buffer < 10){
dateString[3] = '0'; // xx-0x-xxxx xx:xx:xx
dateString[4] = bufferString[0]; // xx-xN-xxxx xx:xx:xx
}else{
dateString[3] = bufferString[0]; // xx-0x-xxxx xx:xx:xx
dateString[4] = bufferString[1]; // xx-xN-xxxx xx:xx:xx
}
//dateString[5] = '-';//Allerede gjort ved initiering
time_buffer = RTC.getYear();
itoa(time_buffer, bufferString, 10);//itoa(heltal som skal konverteres, String buffer, 10 tals systemet);
dateString[6] = bufferString[0]; // xx-xx-Nxxx xx:xx:xx
dateString[7] = bufferString[1]; // xx-xx-xNxx xx:xx:xx
dateString[8] = bufferString[2]; // xx-xx-xxNx xx:xx:xx
dateString[9] = bufferString[3]; // xx-xx-xxxN xx:xx:xx
//dateString[10] = ' ';//Allerede gjort ved initiering
time_buffer = RTC.getHours();
itoa(time_buffer, bufferString, 10);//itoa(heltal som skal konverteres, String buffer, 10 tals systemet);
if(time_buffer < 10){
dateString[11] = '0'; // xx-xx-xxxx 0x:xx:xx
dateString[12] = bufferString[0]; // xx-xx-xxxx xN:xx:xx
}else{
dateString[11] = bufferString[0]; // xx-xx-xxxx Nx:xx:xx
dateString[12] = bufferString[1]; // xx-xx-xxxx xN:xx:xx
}
//dateString[13] = ':';//Allerede gjort ved initiering
time_buffer = RTC.getMinutes();
itoa(time_buffer, bufferString, 10);//itoa(heltal som skal konverteres, String buffer, 10 tals systemet);
if(time_buffer < 10){
dateString[14] = '0'; // xx-xx-xxxx xx:0x:xx
dateString[15] = bufferString[0]; // xx-xx-xxxx xx:xN:xx
}else{
dateString[14] = bufferString[0]; // xx-xx-xxxx xx:Nx:xx
dateString[15] = bufferString[1]; // xx-xx-xxxx xx:xN:xx
}
//dateString[16] = ':';//Allerede gjort ved initiering
time_buffer = RTC.getSeconds();
itoa(time_buffer, bufferString, 10);//itoa(heltal som skal konverteres, String buffer, 10 tals systemet);
if(time_buffer < 10){
dateString[17] = '0'; // xx-xx-xxxx xx:xx:0x
dateString[18] = bufferString[0]; // xx-xx-xxxx xx:xx:xN
}else{
dateString[17] = bufferString[0]; // xx-xx-xxxx xx:xx:Nx
dateString[18] = bufferString[1]; // xx-xx-xxxx xx:xx:xN
}
//Printer ny dato og tid
tft.setCursor(245, 0);
tft.setTextColor(0xFFFF);
tft.print(dateString);//tft.print("4-12-2024 11:42:10");
//ooooooooooooooooooooooooooooooooooooooooooooooooooooo
//----------Top line Out_Temp----------
//ERASE OLD
tft.setCursor(60, 0);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(2);
tft.print("Out:");
tft.print(pageFloatBuffer_0);
tft.write(0xF7);
tft.print("C");
//PRINT NEW
tft.setCursor(60, 0);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(2);
tft.print("Out:");
pageFloatBuffer_0 = average_Out_Temp;
tft.print(average_Out_Temp);
tft.write(0xF7);
tft.print("C");
//ooooooooooooooooooooooooooooooooooooooooooooooooooooo
if (currentPage == 1) { //ooooooooooooooooooooooooooooooo
//--------- Page 1, Box 1--------
bool Braender_pin_cache = digitalRead(Braender_PIN);
if(Braender_pin_cache_old != Braender_pin_cache){
if(Braender_pin_cache){//HIGH == ON
tft.fillRoundRect(4, 34, 472, 72, 6, ST7796S_RED);
}else{//Braender OFF
tft.fillRoundRect(4, 34, 472, 72, 6, ST7796S_BLACK);
}
tft.setCursor(12, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Kedel:");
tft.setCursor(12, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Set:");
Braender_pin_cache_old = Braender_pin_cache;
}
//ERASE OLD
tft.setCursor(260, 40);
if(Braender_pin_cache){//HIGH == ON
tft.setTextColor(ST7796S_RED);
}else{//Braender OFF
tft.setTextColor(ST7796S_BLACK);
}
tft.setTextSize(3);
tft.print(pageFloatBuffer_1);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(260, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_1 = Kedel_Temp;
tft.print(Kedel_Temp);
tft.write(0xF7);
tft.println("C");
//ERASE OLD
tft.setCursor(260, 76);
if(Braender_pin_cache){//HIGH == ON
tft.setTextColor(ST7796S_RED);
}else{//Braender OFF
tft.setTextColor(ST7796S_BLACK);
}
tft.setTextSize(3);
tft.print(pageFloatBuffer_2);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(260, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_2 = Kedel_Set;
tft.print(Kedel_Set);
tft.write(0xF7);
tft.println("C");
//--------------------------------
//---------Page 1, Box 2----------
//ERASE OLD
tft.setCursor(260, 132);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_3);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(260, 132);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_3 = FlowF_Temp;
tft.print(FlowF_Temp);
tft.write(0xF7);
tft.println("C");
//ERASE OLD
tft.setCursor(260, 168);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_4);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(260, 168);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_4 = FlowF_Set;
tft.print(FlowF_Set);
tft.write(0xF7);
tft.println("C");
//---------------------------------
//----------Page 1, Box 3----------
//ERASE OLD
tft.setCursor(260, 224);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_5);
tft.println("% open");
//PRINT NEW
tft.setCursor(260, 224);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_5 = output_Percentage;
tft.print(output_Percentage);
tft.println("% open");
//--------------------------------
//----------Page 1, Box 4---------
//ERASE OLD
tft.setCursor(260, 280);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_6);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(260, 280);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_6 = Chimney_Temp;
tft.print(Chimney_Temp);
tft.write(0xF7);
tft.println("C");
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
}
else if (currentPage == 2) { //ooooooooooooooooooooooooooooooo
//---------Page 2, Box 1--------
//ERASE OLD
tft. setCursor(280, 76);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageUIntBuffer_7);
tft.print(":");
tft.print((int)pageByteBuffer_8);
tft.print(":");
tft.print((int)pageByteBuffer_9);
tft.println(" h");
//PRINT NEW
tft. setCursor(280, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageUIntBuffer_7 = timeBufferTimer_Braender_Flamme;
tft.print(timeBufferTimer_Braender_Flamme);
tft.print(":");
pageByteBuffer_8 = timeBufferMinutter_Braender_Flamme;
tft.print((int)timeBufferMinutter_Braender_Flamme);
tft.print(":");
pageByteBuffer_9 = timeBufferSekunder_Braender_Flamme;
tft.print((int)timeBufferSekunder_Braender_Flamme);
tft.println(" h");
//ERASE OLD
tft. setCursor(280, 112);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_10);
//PRINT NEW
tft. setCursor(280, 112);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_10 = CounterTurnOnTimes_Braender_Flamme;
tft.print(CounterTurnOnTimes_Braender_Flamme);
//-----------------------------------
//------------Page 2, Box 2----------
//ERASE OLD
tft. setCursor(280, 204);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageUIntBuffer_11);
tft.print(":");
tft.print((int)pageByteBuffer_12);
tft.print(":");
tft.print((int)pageByteBuffer_13);
tft.println(" h");
//PRINT NEW
tft. setCursor(280, 204);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageUIntBuffer_11 = timeBufferTimer_CircPump;
tft.print(timeBufferTimer_CircPump);
tft.print(":");
pageByteBuffer_12 = timeBufferMinutter_CircPump;
tft.print((int)timeBufferMinutter_CircPump);
tft.print(":");
pageByteBuffer_13 = timeBufferSekunder_CircPump;
tft.print((int)timeBufferSekunder_CircPump);
tft.println(" h");
//ERASE OLD
tft. setCursor(280, 240);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_14);
//PRINT NEW
tft. setCursor(280, 240);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_14 = CounterTurnOnTimes_CircPump;
tft.print(CounterTurnOnTimes_CircPump);
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
}
else if (currentPage == 3) { //ooooooooooooooooooooooooooooooo
//-----------Page 3, Box 1----------
//ERASE OLD
tft.setCursor(280, 40);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_15);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_15 = Cwater_Temp;
tft.print(Cwater_Temp);
tft.write(0xF7);
tft.println("C");
//---------------------------------
//----------Page 3, Box 2----------
//ERASE OLD
tft.setCursor(280, 96);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_16);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 96);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_16 = Wwater_Temp;
tft.print(Wwater_Temp);
tft.write(0xF7);
tft.println("C");
//--------------------------------
//----------Page 3, Box 3---------
//ERASE OLD
tft.setCursor(280, 152);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_17);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 152);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_17 = Kedel_Temp;
tft.print(Kedel_Temp);
tft.write(0xF7);
tft.println("C");
//ERASE OLD
tft.setCursor(280, 188);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_18);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 188);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_18 = Kedel_Set;
tft.print(Kedel_Set);
tft.write(0xF7);
tft.println("C");
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
}
else if (currentPage == 4) { //ooooooooooooooooooooooooooooooo
//----------Page 4, Box 1----------
//ERASE OLD
tft.setCursor(280,40);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_19);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280,40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_19 = FlowF_Temp;
tft.print(FlowF_Temp);
tft.write(0xF7);
tft.println("C");
//ERASE OLD
tft.setCursor(280, 76);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_20);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_20 = FlowF_Set;
tft.print(FlowF_Set);
tft.write(0xF7);
tft.println("C");
//---------------------------------
//-----------Page 4, Box 2---------
//ERASE OLD
tft.setCursor(280, 132);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_21);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 132);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_21 = FlowR_Temp;
tft.print(FlowR_Temp);
tft.write(0xF7);
tft.println("C");
//---------------------------------
//----------Page 4, Box 3----------
//ERASE OLD
tft. setCursor(280, 224);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_22);
tft.print("%");
//PRINT NEW
tft. setCursor(280, 224);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_22 = output_Percentage;
tft.print(output_Percentage);
tft.print("%");
//ERASE OLD
tft. setCursor(280, 260);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_23);
tft.write(0xF7);
//PRINT NEW
tft. setCursor(280, 260);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_23 = output;
tft.print(output);
tft.write(0xF7);
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
}
else if (currentPage == 5) { //ooooooooooooooooooooooooooooooo
//----------Page 5, Box 1-----------
//ERASE OLD
tft.setCursor(280, 40);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_24);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_24 = Out_Temp_Sensor1;
tft.print(Out_Temp_Sensor1);
tft.write(0xF7);
tft.println("C");
//----------------------------------
//----------Page 5, Box 2-----------
//ERASE OLD
tft.setCursor(280, 96);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_25);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 96);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_25 = Out_Temp_Sensor2;
tft.print(Out_Temp_Sensor2);
tft.write(0xF7);
tft.println("C");
//----------------------------------
//----------Page 5, Box 3-----------
//ERASE OLD
tft.setCursor(280, 152);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_26);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 152);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_26 = average_Out_Temp;
tft.print(average_Out_Temp);
tft.write(0xF7);
tft.println("C");
//----------------------------------
//----------Page 5, Box 4-----------
//ERASE OLD
tft.setCursor(280, 208);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_27);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 208);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_27 = Kedel_Set;
tft.print(Kedel_Set);
tft.write(0xF7);
tft.println("C");
//----------------------------------
//----------Page 5, Box 5-----------
//ERASE OLD
tft.setCursor(280, 264);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_28);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 264);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_28 = FlowF_Set;
tft.print(FlowF_Set);
tft.write(0xF7);
tft.println("C");
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
}
else if (currentPage == 6) { //ooooooooooooooooooooooooooooooo
//----------Page 6, Box 1----------
//ERASE OLD
tft.setCursor(280, 40);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_29);
tft.write(0xF7);
tft.println("C");
//PRINT NEW
tft.setCursor(280, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_29 = Box_Temp;
tft.print(Box_Temp);
tft.write(0xF7);
tft.println("C");
//ERASE OLD
tft.setCursor(280, 76);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_30);
tft.println("%");
//PRINT NEW
tft.setCursor(280, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_30 = Blaeser_Output_Procent;
tft.print(Blaeser_Output_Procent);
tft.println("%");
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
}
else if (currentPage == 7) { //ooooooooooooooooooooooooooooooo
//----------Page 7, Box 1-----------
//ERASE OLD
tft.setCursor(90, 76);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_31);
tft.println(" Volt.");
//PRINT NEW
tft.setCursor(90, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_31 = Out_12vdc_V;
tft.print(Out_12vdc_V);
tft.println(" Volt.");
//ERASE OLD
tft.setCursor(330, 76);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_32);
tft.println(" A.");
//PRINT NEW
tft.setCursor(330, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_32 = Out_12vdc_mA;
tft.print(Out_12vdc_mA);
tft.println(" A.");
//---------------------------------
//----------Page 7, Box 2----------
//ERASE OLD
tft.setCursor(90, 168);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_33);
tft.println(" Volt.");
//PRINT NEW
tft.setCursor(90, 168);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_33 = Arduino_V;
tft.print(Arduino_V);
tft.println(" Volt.");
//ERASE OLD
tft.setCursor(330, 168);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_34);
tft.println(" A.");
//PRINT NEW
tft.setCursor(330, 168);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_34 = Arduino_mA;
tft.print(Arduino_mA);
tft.println(" A.");
//---------------------------------
//----------Page 7, Box 3----------
//ERASE OLD
tft.setCursor(90, 260);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_35);
tft.println(" Volt.");
//PRINT NEW
tft.setCursor(90, 260);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_35 = Servo_V;
tft.print(Servo_V);
tft.println(" Volt.");
//ERASE OLD
tft.setCursor(330, 260);
tft.setTextColor(ST7796S_BLACK);
tft.setTextSize(3);
tft.print(pageFloatBuffer_36);
tft.println(" A.");
//PRINT NEW
tft.setCursor(330, 260);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_36 = Servo_mA;
tft.print(Servo_mA);
tft.println(" A.");
//oooooooooooooooooooooooooooooooooooooooooooooooooooooo
}
}
void changePage(int page) { //function to change the page based on the current page number
tft.fillScreen(0); //clear the screen
//---------- Top line on all page--------
tft.setCursor(3, 0);
tft.setTextColor(0xFFFF);
tft.setTextSize(1);
tft.print("Page_");
tft.print(currentPage);
tft.setCursor(60, 0);
tft.setTextColor(0xFFFF);
tft.setTextSize(2);
tft.print("Out:");
pageFloatBuffer_0 = average_Out_Temp;
tft.print(average_Out_Temp);
tft.write(0xF7);
tft.print("C");
if (page == 1) { //if the current page is 1
//--------- Page 1, Box 1--------
tft.fillRoundRect(0, 30, 480, 80, 10, 0xFD20);//Orange
bool Braender_pin_cache = digitalRead(Braender_PIN);
if(Braender_pin_cache){//HIGH == ON
tft.fillRoundRect(4, 34, 472, 72, 6, ST7796S_RED);
}else{//Braender OFF
tft.fillRoundRect(4, 34, 472, 72, 6, ST7796S_BLACK);
}
Braender_pin_cache_old = Braender_pin_cache;
tft.setCursor(12, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Kedel:");
tft.setCursor(260, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_1 = Kedel_Temp;
tft.print(Kedel_Temp);
tft.write(0xF7);
tft.println("C");
tft.setCursor(12, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Set:");
tft.setCursor(260, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_2 = Kedel_Set;
tft.print(Kedel_Set);
tft.write(0xF7);
tft.println("C");
//--------------------------------
//---------Page 1, Box 2----------
tft.fillRoundRect(0, 122, 480, 80, 10, 0xF800);//Red
tft.fillRoundRect(4, 126, 472, 72, 6, ST7796S_BLACK);
tft.setCursor(12, 132);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("FlowF:");
tft.setCursor(260, 132);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_3 = FlowF_Temp;
tft.print(FlowF_Temp);
tft.write(0xF7);
tft.println("C");
tft.setCursor(12, 168);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Set:");
tft.setCursor(260, 168);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_4 = FlowF_Set;
tft.print(FlowF_Set);
tft.write(0xF7);
tft.println("C");
//---------------------------------
//----------Page 1, Box 3----------
tft.fillRoundRect(0, 214, 480, 44, 10, 0x780F);//Purple
tft.fillRoundRect(4, 218, 472, 36, 6, ST7796S_BLACK);
tft.setCursor(12, 224);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Shunt:");
tft.setCursor(260, 224);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_5 = output_Percentage;
tft.print(output_Percentage);
tft.println("% open");
//-----------Page 1, Box 4---------
tft.fillRoundRect(0, 270, 480, 44, 10, 0xFFE0);//Yellow
tft.fillRoundRect(4, 274, 472, 36, 6, ST7796S_BLACK);
tft.setCursor(12, 280);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Chimney");
tft.setCursor(260, 280);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_6 = Chimney_Temp;
tft.print(Chimney_Temp);
tft.write(0xF7);
tft.println("C");
//--------------------------------
}
else if (page == 2) { //if the current page is 2
//----------Page 2, Box 1----------
tft.fillRoundRect(0, 30, 480, 116, 10, 0xFD20);//Orange
tft.fillRoundRect(4, 34, 472, 108, 6, ST7796S_BLACK);
tft.setCursor(12, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Braender Flamme.");
tft.setCursor(12, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Drifts tid:");
tft. setCursor(280, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageUIntBuffer_7 = timeBufferTimer_Braender_Flamme;
tft.print(timeBufferTimer_Braender_Flamme);
tft.print(":");
pageByteBuffer_8 = timeBufferMinutter_Braender_Flamme;
tft.print((int)timeBufferMinutter_Braender_Flamme);
tft.print(":");
pageByteBuffer_9 = timeBufferSekunder_Braender_Flamme;
tft.print((int)timeBufferSekunder_Braender_Flamme);
tft.println(" h");
tft.setCursor(12, 112);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Start Counter:");
tft. setCursor(280, 112);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_10 = CounterTurnOnTimes_Braender_Flamme;
tft.print(CounterTurnOnTimes_Braender_Flamme);
//--------------------------------
//----------Page 2, Box2----------
tft.fillRoundRect(0, 158, 480, 116, 10, 0xF800);//Red
tft.fillRoundRect(4, 162, 472, 108, 6, ST7796S_BLACK);
tft.setCursor(12, 168);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("CircPump.");
tft.setCursor(12, 204);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Drifts tid:");
tft. setCursor(280, 204);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageUIntBuffer_11 = timeBufferTimer_CircPump;
tft.print(timeBufferTimer_CircPump);
tft.print(":");
pageByteBuffer_12 = timeBufferMinutter_CircPump;
tft.print((int)timeBufferMinutter_CircPump);
tft.print(":");
pageByteBuffer_13 = timeBufferSekunder_CircPump;
tft.print((int)timeBufferSekunder_CircPump);
tft.println(" h");
tft.setCursor(12, 240);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Start Counter:");
tft. setCursor(280, 240);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_14 = CounterTurnOnTimes_CircPump;
tft.print(CounterTurnOnTimes_CircPump);
//---------------------------------
}
else if (page == 3) { //if the current page is 2
//----------Page 3, Box 1----------
tft.fillRoundRect(0, 30, 480, 44, 10, 0x001F);//Blue
tft.fillRoundRect(4, 34, 472, 36, 6, ST7796S_BLACK);
tft.setCursor(12, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Cwater");
tft.setCursor(280, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_15 = Cwater_Temp;
tft.print(Cwater_Temp);
tft.write(0xF7);
tft.println("C");
//--------------------------------
//----------Page 3, Box 2---------
tft.fillRoundRect(0, 86, 480, 44, 10, 0xF800);//Red
tft.fillRoundRect(4, 90, 472, 36, 6, ST7796S_BLACK);
tft.setCursor(12, 96);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Wwater:");
tft.setCursor(280, 96);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_16 = Wwater_Temp;
tft.print(Wwater_Temp);
tft.write(0xF7);
tft.println("C");
//--------------------------------
//----------Page 3, Box 3---------
tft.fillRoundRect(0, 142, 480, 80, 10, 0xFD20);//Orange
tft.fillRoundRect(4, 146, 472, 72, 6, ST7796S_BLACK);
tft.setCursor(12, 152);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Kedel:");
tft.setCursor(280, 152);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_17 = Kedel_Temp;
tft.print(Kedel_Temp);
tft.write(0xF7);
tft.println("C");
tft.setCursor(12, 188);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Set:");
tft.setCursor(280, 188);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_18 = Kedel_Set;
tft.print(Kedel_Set);
tft.write(0xF7);
tft.println("C");
//--------------------------------
}
else if (page == 4) { //if the current page is 2
//----------Page 4, Box 1----------
tft.fillRoundRect(0, 30, 480, 80, 10, 0xF800);//Red
tft.fillRoundRect(4, 34, 472, 72, 6, ST7796S_BLACK);
tft.setCursor(12, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("FlowF:");
tft.setCursor(280, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_19 = FlowF_Temp;
tft.print(FlowF_Temp);
tft.write(0xF7);
tft.println("C");
tft.setCursor(12, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Set:");
tft.setCursor(280, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_20 = FlowF_Set;
tft.print(FlowF_Set);
tft.write(0xF7);
tft.println("C");
//---------------------------------
//----------Page 4, Box 2----------
tft.fillRoundRect(0, 122, 480, 44, 10, 0x001F);//Blue
tft.fillRoundRect(4, 126, 472, 36, 6, ST7796S_BLACK);
tft.setCursor(12, 132);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("FlowR:");
tft.setCursor(280, 132);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_21 = FlowR_Temp;
tft.print(FlowR_Temp);
tft.write(0xF7);
tft.println("C");
//--------------------------------
//---------Page 4, Box 3----------
tft.fillRoundRect(0, 178, 480, 116, 10, 0x780F);//Purple
tft.fillRoundRect(4, 182, 472, 108, 6, ST7796S_BLACK);
tft.setCursor(12, 188);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Shunt.");
tft.setCursor(12, 224);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Open:");
tft. setCursor(280, 224);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_22 = output_Percentage;
tft.print(output_Percentage);
tft.print("%");
tft.setCursor(12, 260);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Angel pos:");
tft. setCursor(280, 260);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_23 = output;
tft.print(output);
tft.write(0xF7);
//---------------------------------
}
else if (page == 5) { //if the current page is 2
//----------Page 5, Box 1----------
tft.fillRoundRect(0, 30, 480, 44, 10, 0xC618);//LightGrey
tft.fillRoundRect(4, 34, 472, 36, 6, ST7796S_BLACK);
tft.setCursor(12, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Out sensor 1:");
tft.setCursor(280, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_24 = Out_Temp_Sensor1;
tft.print(Out_Temp_Sensor1);
tft.write(0xF7);
tft.println("C");
//---------------------------------
//----------Page 5, Box 2----------
tft.fillRoundRect(0, 86, 480, 44, 10, 0xC618);//LightGrey
tft.fillRoundRect(4, 90, 472, 36, 6, ST7796S_BLACK);
tft.setCursor(12, 96);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Out sensor 2:");
tft.setCursor(280, 96);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_25 = Out_Temp_Sensor2;
tft.print(Out_Temp_Sensor2);
tft.write(0xF7);
tft.println("C");
//---------------------------------
//----------Page 5, Box 3----------
tft.fillRoundRect(0, 142, 480, 44, 10, 0xC618);//LightGrey
tft.fillRoundRect(4, 146, 472, 36, 6, ST7796S_BLACK);
tft.setCursor(12, 152);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Out average:");
tft.setCursor(280, 152);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_26 = average_Out_Temp;
tft.print(average_Out_Temp);
tft.write(0xF7);
tft.println("C");
//---------------------------------
//----------Page 5, Box 4----------
tft.fillRoundRect(0, 198, 480, 44, 10, 0xFD20);//Orange
tft.fillRoundRect(4, 202, 472, 36, 6, ST7796S_BLACK);
tft.setCursor(12, 208);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Kedel set:");
tft.setCursor(280, 208);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_27 = Kedel_Set;
tft.print(Kedel_Set);
tft.write(0xF7);
tft.println("C");
//---------------------------------
//----------Page 5, Box 5----------
tft.fillRoundRect(0, 254, 480, 44, 10, 0xF800);//Red
tft.fillRoundRect(4, 258, 472, 36, 6, ST7796S_BLACK);
tft.setCursor(12, 264);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("FlowF set:");
tft.setCursor(280, 264);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_28 = FlowF_Set;
tft.print(FlowF_Set);
tft.write(0xF7);
tft.println("C");
//---------------------------------
}
else if (page == 6) { //if the current page is 2
//----------Page 6, Box 1----------
tft.fillRoundRect(0, 30, 480, 80, 10, ST7796S_GREEN);
tft.fillRoundRect(4, 34, 472, 72, 6, ST7796S_BLACK);
tft.setCursor(12, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Box:");
tft.setCursor(280, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_29 = Box_Temp;
tft.print(Box_Temp);
tft.write(0xF7);
tft.println("C");
tft.setCursor(12, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Blaeser:");
tft.setCursor(280, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_30 = Blaeser_Output_Procent;
tft.print(Blaeser_Output_Procent);
tft.println("%");
//---------------------------------
}
else if (page == 7) { //if the current page is 2
//----------Page 7, Box 1----------
tft.fillRoundRect(0, 30, 480, 80, 10, 0xF81F);//Magenta
tft.fillRoundRect(4, 34, 472, 72, 6, ST7796S_BLACK);
tft.setCursor(12, 40);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("12vdc supply");
tft.setCursor(90, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_31 = Out_12vdc_V;
tft.print(Out_12vdc_V);
tft.println(" Volt.");
tft.setCursor(330, 76);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_32 = Out_12vdc_mA;
tft.print(Out_12vdc_mA);
tft.println(" A.");
//---------------------------------
//----------Page 7, Box 2----------
tft.fillRoundRect(0, 122, 480, 80, 10, 0xF81F);//Magenta
tft.fillRoundRect(4, 126, 472, 72, 6, ST7796S_BLACK);
tft.setCursor(12, 132);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Arduino supply");
tft.setCursor(90, 168);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_33 = Arduino_V;
tft.print(Arduino_V);
tft.println(" Volt.");
tft.setCursor(330, 168);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_34 = Arduino_mA;
tft.print(Arduino_mA);
tft.println(" A.");
//---------------------------------
//----------Page 7, Box 3----------
tft.fillRoundRect(0, 214, 480, 80, 10, 0xF81F);//Magenta
tft.fillRoundRect(4, 218, 472, 72, 6, ST7796S_BLACK);
tft.setCursor(12, 224);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
tft.print("Servo(shunt) supply");
tft.setCursor(90, 260);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_35 = Servo_V;
tft.print(Servo_V);
tft.println(" Volt.");
tft.setCursor(330, 260);
tft.setTextColor(ST7796S_WHITE);
tft.setTextSize(3);
pageFloatBuffer_36 = Servo_mA;
tft.print(Servo_mA);
tft.println(" A.");
//--------------------------------
}
}
void TFT_loop(void *pvParameters){
while(true){
vTaskDelay( 100 / portTICK_PERIOD_MS );
//--------------------TFT Code-----------------------
if (digitalRead(MENU_FORWARD_BUTTON_PIN) == HIGH) {
currentPage++; //increment the current page
if (currentPage > 7) { //if the current page is greater than 2, reset it to 1
currentPage = 1;
}
changePage(currentPage); //call the function to change the page
lastScreenUpdate = millis();
delay(100); //debounce delay
}
if (digitalRead(MENU_BACK_BUTTON_PIN) == HIGH) { //check if the second button is pressed
currentPage--; //decrement the current page
if (currentPage < 1) { //if the current page is less than 1, reset it to 2
currentPage = 7;
}
changePage(currentPage); //call the function to change the page
lastScreenUpdate = millis();
delay(100); //debounce delay
}
if(millis() - lastScreenUpdate > IntervalScreenUpdate){
updatePage();//Laver løbende opdatering med lavt resourceforbrug.
lastScreenUpdate = millis();
}
}
}
#define Kedel_Temp_offset 0.0
#define FlowF_Temp_offset 0.0
#define FlowR_Temp_offset 0.0
#define Cwater_Temp_offset 0.0
#define Wwater_Temp_offset 0.0
#define Out_Temp_Sensor1_offset -2.0
#define Out_Temp_Sensor2_offset -1.5
#define Box_Temp_offset 0.0
#define Chimney_Temp_offset 0.0
void Sensors_loop(void *pvParameters){
while(true){
vTaskDelay( 500 / portTICK_PERIOD_MS );
sensors.requestTemperatures();
float Unverified_Kedel_Temp = sensors.getTempC(Kedel_Temp_Adr);
if( (-20.0 < Unverified_Kedel_Temp) && (Unverified_Kedel_Temp < 100.0)){
//Data is validated and can be used for decition making
Kedel_Temp = Unverified_Kedel_Temp + Kedel_Temp_offset;
}
float Unverified_FlowF_Temp = sensors.getTempC(FlowF_Temp_addr);
if( (-20.0 < Unverified_FlowF_Temp) && (Unverified_FlowF_Temp < 100.0)){
//Data is validated and can be used for decition making
FlowF_Temp = Unverified_FlowF_Temp + FlowF_Temp_offset;
}
float Unverified_FlowR_Temp = sensors.getTempC(FlowR_Temp_addr);
if( (-20.0 < Unverified_FlowR_Temp) && (Unverified_FlowR_Temp < 100.0)){
//Data is validated and can be used for decition making
FlowR_Temp = Unverified_FlowR_Temp + FlowR_Temp_offset;
}
float Unverified_Cwater_Temp = sensors.getTempC(Cwater_Temp_addr);
if( (-20.0 < Unverified_Cwater_Temp) && (Unverified_Cwater_Temp < 100.0)){
//Data is validated and can be used for decition making
Cwater_Temp = Unverified_Cwater_Temp + Cwater_Temp_offset;
}
float Unverified_Wwater_Temp = sensors.getTempC(Wwater_Temp_addr);
if( (-20.0 < Unverified_Wwater_Temp) && (Unverified_Wwater_Temp < 100.0)){
//Data is validated and can be used for decition making
Wwater_Temp = Unverified_Wwater_Temp + Wwater_Temp_offset;
}
float Unverified_Out_Temp_Sensor1 = sensors.getTempC(Out_Temp_Sensor1_addr);
if( (-40.0 < Unverified_Out_Temp_Sensor1) && (Unverified_Out_Temp_Sensor1 < 100.0)){
//Data is validated and can be used for decition making
Out_Temp_Sensor1 = Unverified_Out_Temp_Sensor1 + Out_Temp_Sensor1_offset;
}
float Unverified_Out_Temp_Sensor2 = sensors.getTempC(Out_Temp_Sensor2_addr);
if( (-40.0 < Unverified_Out_Temp_Sensor2) && (Unverified_Out_Temp_Sensor2 < 100.0)){
//Data is validated and can be used for decition making
Out_Temp_Sensor2 = Unverified_Out_Temp_Sensor2 + Out_Temp_Sensor2_offset;
}
float Unverified_Box_Temp = sensors.getTempC(Box_Temp_addr);
if( (-40.0 < Unverified_Box_Temp) && (Unverified_Box_Temp < 100.0)){
//Data is validated and can be used for decition making
Box_Temp = Unverified_Box_Temp + Box_Temp_offset;
}
float Unverified_Chimney_Temp = sensors.getTempC(Chimney_Temp_addr);
if( (-40.0 < Unverified_Chimney_Temp) && (Unverified_Chimney_Temp < 100.0)){
//Data is validated and can be used for decition making
Chimney_Temp = Unverified_Chimney_Temp + Chimney_Temp_offset;
}
float average_Out_Temp_new = (Out_Temp_Sensor1 + Out_Temp_Sensor2) / 2; //--Calculate average Out_Temp_Sensor's
float Smooth_factor = 0.001;// 0 -> 1.0 ||| [0=Langsomt/intet respons] [1.0=Hurtigt respons]
if(SmoothFirstRun){//Køres kun første gang under opstart
average_Out_Temp = average_Out_Temp_new;
SmoothFirstRun = false;
}
average_Out_Temp = (average_Out_Temp_new * Smooth_factor) + (average_Out_Temp * (1.0 - Smooth_factor));
Out_12vdc_V = ina226_Out_12vdc.getBusVoltage_V();
Out_12vdc_mA = ina226_Out_12vdc.getCurrent_mA() / 1000;
Servo_V = ina226_Servo.getBusVoltage_V();
Servo_mA = ina226_Servo.getCurrent_mA() / 1000;
Arduino_V = ina226_Arduino.getBusVoltage_V();
Arduino_mA = ina226_Arduino.getCurrent_mA() / 1000;
SensorsReady = true;
SyncUpdatePID_Flag = !SyncUpdatePID_Flag;//Flip bit. Tell a update of data was done.
lastSensorsUpdate = millis();
}
}
void IO_loop(void *pvParameters){
//LOCAL SETUP
pinMode(Stop_Servo_Tid_Pin, OUTPUT);
digitalWrite(Stop_Servo_Tid_Pin, HIGH);//Turn on servo power
while(true){
vTaskDelay( 200 / portTICK_PERIOD_MS );
while(!SensorsReady){//Wait for sensors to be read before taking decitions.
vTaskDelay( 500 / portTICK_PERIOD_MS );
}
servo.write(output);
//output_Percentage = map(output, 50, 140, 0, 100); //-----Servo Angel to percentage
output_Percentage = (output - 0.0) * ((100.0) / (130.0 - 0.0)) ;
//Servo power off if stading still at endges
if(output_Percentage < 2.0 || 98.0 < output_Percentage)
{
if(millis() - Stop_Servo_Tid_PowerREQ > Stop_Servo_Tid_PowerREQ_OnTime)
{//Time exceeded turn off servo power
digitalWrite(Stop_Servo_Tid_Pin, LOW);//Turn off servo power
}
else
{
digitalWrite(Stop_Servo_Tid_Pin, HIGH);//Turn on servo power
}
}
else
{//Always on
digitalWrite(Stop_Servo_Tid_Pin, HIGH);//Turn on servo power
}
if(abs(output_Percentage - Stop_Servo_Tid_PowerREQ_servoPos) > Stop_Servo_Tid_Hys)
{
Stop_Servo_Tid_PowerREQ_servoPos = output_Percentage;//Save new position
Stop_Servo_Tid_PowerREQ = millis();//Set timer to noew and trigger servo power on
}
//============================== FlowF Map and limits ===================================
FlowF_Set = fmap(average_Out_Temp, -14, 17, 56, 46); //-----Mapped Setpoint Flow_Set to PID
if(FlowF_Set > 56){ //-------------------------------------------FlowF_Set upper limit
FlowF_Set = 56;
}else if(FlowF_Set < 47){ //-------------------------------------FlowF_Set lower limit
FlowF_Set = 47;
}
//=======================================================================================
//============================= Kedel Map and limits ===================================
Kedel_Set = fmap(average_Out_Temp, -14, 17, 70, 60); //-----Mapped Out_Temp to Setpoint Kedel_Set
if(Kedel_Set > 70){ //-----upper limit
Kedel_Set = 70;
}else if(Kedel_Set < 60){ //-----Kedel_Set lower limit
Kedel_Set = 60;
}
//======================================================================================
//============================ Blaeser / map() til procent ==================================
if(Box_Temp > 39){
Blaeser_Output = 255;
}
else if((Box_Temp > 37) && (Blaeser_Output < 80)){
Blaeser_Output = 80;
}
else if(( Box_Temp > 35) && (Blaeser_Output < 30)){ //------------------------------------Min 30, ellers stater blaeseren ikke.
Blaeser_Output = 30;
}
else if(Box_Temp < 34){
Blaeser_Output = 0;
}
pwm_Blaeser_PIN.writeScaled(Blaeser_Output/255.0);
Blaeser_Output_Procent = fmap(Blaeser_Output, 0, 255, 0, 100);
//=====================================================================================
if(Kedel_Temp < (Kedel_Set - Kedel_Hys)){
digitalWrite(Braender_PIN, HIGH);
}
else if (Kedel_Temp > (Kedel_Set)){
digitalWrite(Braender_PIN, LOW);
}
//------------------------------Function to stop CircPump and close Shunt(Servo)-------------------//
if(digitalRead(Stop_Pump_Servo_PIN)){
output = 0; //---------------------------------------------------Shunt(servo) close to when Stop_Pump_Servo function activate, remember line 77 too
}
else{
if(SyncUpdatePID_Flag != SyncUpdatePID_LatestUpdate){
myPID.Compute();
SyncUpdatePID_LatestUpdate = SyncUpdatePID_Flag;//Tell latest sensor data was handled
}
}
if(digitalRead(Stop_Pump_Servo_PIN)){
if(millis() - lastTimeFinishedInterval > MaxTimeOff){
digitalWrite(CircPump_PIN, HIGH);
}else{
digitalWrite(CircPump_PIN, LOW);
}
}else{
if(average_Out_Temp < (CircPump_Set - CircPump_Hys)){
digitalWrite(CircPump_PIN, HIGH);
}
else if(average_Out_Temp > (CircPump_Set)){
if(millis() - lastTimeFinishedInterval > MaxTimeOff){
digitalWrite(CircPump_PIN, HIGH);
}else{
digitalWrite(CircPump_PIN, LOW);
}
}
}
if(digitalRead(CircPump_PIN) != CirPumpOldState){
if(digitalRead(CircPump_PIN)){
lastTimeBeginOn = millis();
}else{
lastTimeBeginOff = millis();
}
CirPumpOldState = digitalRead(CircPump_PIN);
}
if(digitalRead(CircPump_PIN)){
if(millis() - lastTimeBeginOn > TimeToBeOn){
lastTimeFinishedInterval = millis();
}
}
lastIOloopUpdate = millis();
}
}
void Counter_loop(void *pvParameters){
while(true){
vTaskDelay( 300 / portTICK_PERIOD_MS );
long RTC_millis = (1000 * (unsigned long)RTC.getEpoch());
//-----------------------------Start up counter Braender_Flamme-------------------------------------//
if(digitalRead(Braender_Flamme_PIN) != lastState_Braender_Flamme){
if(lastState_Braender_Flamme){
timeBufferSekunder_Braender_Flamme += (RTC_millis - timerStart_Braender_Flamme)/1000;
}else{
timerStart_Braender_Flamme = RTC_millis;
CounterTurnOnTimes_Braender_Flamme++;
}
lastState_Braender_Flamme = digitalRead(Braender_Flamme_PIN);
}//----------------------------------------------------------------------------------------------//
//------------------------------ Timeshift code Braender_Flamme.... s -> min -> timer --------------//
if(RTC_millis - timerStart_Braender_Flamme > 1000 && digitalRead(Braender_Flamme_PIN)){
timeBufferSekunder_Braender_Flamme++;
timerStart_Braender_Flamme += 1000;
if(timeBufferSekunder_Braender_Flamme > 59){
timeBufferSekunder_Braender_Flamme -= 60;
timeBufferMinutter_Braender_Flamme++;
if(timeBufferMinutter_Braender_Flamme > 59){
timeBufferMinutter_Braender_Flamme -= 60;
timeBufferTimer_Braender_Flamme++;
}//-----------------------------------------------------------------------------------------//
}
}
//-----------------------------Start up counter Circ_Pump--------------------------------------//
if(digitalRead(CircPump_PIN) != lastState_CircPump){
if(lastState_CircPump){
timeBufferSekunder_CircPump += (RTC_millis - timerStart_CircPump)/1000;
}else{
timerStart_CircPump = RTC_millis;
CounterTurnOnTimes_CircPump++;
}
lastState_CircPump = digitalRead(CircPump_PIN);
}//-------------------------------------------------------------------------------------------//
//------------------------------ Timeshift code CircPump.... s -> min -> timer----------------//
if(RTC_millis - timerStart_CircPump > 1000 && digitalRead(CircPump_PIN)){
timeBufferSekunder_CircPump++;
timerStart_CircPump += 1000;
if(timeBufferSekunder_CircPump > 59){
timeBufferSekunder_CircPump -= 60;
timeBufferMinutter_CircPump++;
if(timeBufferMinutter_CircPump > 59){
timeBufferMinutter_CircPump -= 60;
timeBufferTimer_CircPump++;
}//---------------------------------------------------------------------------------------//
}
}
lastCounterLoopUpdate = millis();
}
}
void FRAM_updater(void *pvParameters){
while(true){
vTaskDelay( 100 / portTICK_PERIOD_MS );
//Write data to FRAM every 5s
if(millis() - lastFRAMwrite > 10000){
if(FRAM_OK){
//Move data from variables to FRAM
/*VARIABLE : FRAM address
unsigned int timeBufferTimer_Braender_Flamme : 0-1 (2 bytes)
unsigned int timeBufferTimer_CircPump : 2-3 (2 bytes)
byte timeBufferMinutter_Braender_Flamme : 4
byte timeBufferMinutter_CircPump : 5
byte timeBufferSekunder_Braender_Flamme : 6
byte timeBufferSekunder_CircPump : 7
unsigned int CounterTurnOnTimes_Braender_Flamme: 8-9 (2 bytes)
unsigned int CounterTurnOnTimes_CircPump : 10-11 (2 bytes)
*/
//---timeBufferTimer_Braender_Flamme
fram.write(0, timeBufferTimer_Braender_Flamme );//Only some of the data will fit! Rest will overflow(be removed).
fram.write(1, timeBufferTimer_Braender_Flamme >> 8);//Rest of data is handled here
//---timeBufferTimer_CircPump
fram.write(2, timeBufferTimer_CircPump );//Only some of the data will fit! Rest will overflow(be removed).
fram.write(3, timeBufferTimer_CircPump >> 8 );//Rest of data is handled here
//---timeBufferMinutter_Braender_Flamme
fram.write(4, timeBufferMinutter_Braender_Flamme);
//---timeBufferMinutter_CircPump
fram.write(5, timeBufferMinutter_CircPump );
//---timeBufferSekunder_Braender_Flamme
fram.write(6, timeBufferSekunder_Braender_Flamme);
//---timeBufferSekunder_CircPump
fram.write(7, timeBufferSekunder_CircPump );
//---CounterTurnOnTimes_Braender_Flamme
fram.write(8, CounterTurnOnTimes_Braender_Flamme );//Only some of the data will fit! Rest will overflow(be removed).
fram.write(9, CounterTurnOnTimes_Braender_Flamme >> 8);//Rest of data is handled here
//---CounterTurnOnTimes_CircPump
fram.write(10, CounterTurnOnTimes_CircPump );//Only some of the data will fit! Rest will overflow(be removed).
fram.write(11, CounterTurnOnTimes_CircPump >> 8);//Rest of data is handled here
printDebugln("FRAM updated");
}else{
printDebugln("<<!!!>> FRAM not connected. Please try to restart. <<!!!>>");
}
lastFRAMwrite = millis();
}
}
}
void Serial_updater(void *pvParameters){
while(true){
vTaskDelay( 100 / portTICK_PERIOD_MS );
if(((millis() - lastPrintUpdate > IntervalPrintUpdate) ) || ((millis() - lastPrintUpdate > IntervalPlotterUpdate) && PlotterMode) ){//
printDebug("Kedel_Temp: ");
printDebug(Kedel_Temp);
printDebug(" / Kedel_Set: ");
printDebugln(Kedel_Set);
vTaskDelay( 50 / portTICK_PERIOD_MS );
//------------------------------Printer running time and startup's Braender--------------------//
printDebug("Tid_Braender_Flamme: ");
printDebug(timeBufferTimer_Braender_Flamme);
printDebug("h ");
printDebug(timeBufferMinutter_Braender_Flamme);
printDebug("m ");
printDebug(timeBufferSekunder_Braender_Flamme);
printDebug("s ");
printDebug("/ Start_Up: ");
printDebug(CounterTurnOnTimes_Braender_Flamme);
printDebugln(" times");
printDebugln("");
vTaskDelay( 50 / portTICK_PERIOD_MS );
//------------------------------------------------------------------------------------------//
printDebug("FlowF_Temp: ");
printDebug(FlowF_Temp);
printDebug(" / FlowF_Set: ");
printDebug(FlowF_Set);
printDebug(" / Shunt_Pos: ");
printDebug(output);
printDebug(" / Shunt % Open: ");
printDebugln(output_Percentage);
printDebug("FlowR_Temp: ");
printDebugln(FlowR_Temp);
printDebugln("");
printDebug("Cwater_Temp: ");
printDebugln(Cwater_Temp);
printDebug("Wwater_Temp: ");
printDebugln(Wwater_Temp);
printDebugln("");
printDebug("Chimney_Temp");
printDebugln(Chimney_Temp);
printDebugln("");
vTaskDelay( 50 / portTICK_PERIOD_MS );
//------------------------------Printer running time and startup´s CircPump----------------//
printDebug("Running_Time_CircPump: ");
printDebug(timeBufferTimer_CircPump);
printDebug("h ");
printDebug(timeBufferMinutter_CircPump);
printDebug("m ");
printDebug(timeBufferSekunder_CircPump);
printDebug("s ");
printDebug("/ Start_Up: ");
printDebug(CounterTurnOnTimes_CircPump);
printDebugln(" times");
printDebugln("");
vTaskDelay( 50 / portTICK_PERIOD_MS );
//----------------------------------------------------------------------------------------//
printDebug("Out_Temp: ");
printDebug(average_Out_Temp);
printDebug(" / Out_Temp_Sensor1: ");
printDebug(Out_Temp_Sensor1);
printDebug(" / Out_Temp_Sensor2: ");
printDebugln(Out_Temp_Sensor2);
printDebugln("");
printDebug("Box_Temp: ");
printDebugln(Box_Temp);
printDebug("Blaeser_output: ");
printDebugln(Blaeser_Output);
printDebugln("");
vTaskDelay( 50 / portTICK_PERIOD_MS );
printDebug("Out_12vdc_Volt: ");
printDebugln(Out_12vdc_V);
printDebug("Out_12vdc_mA: ");
printDebugln(Out_12vdc_mA);
printDebug("Servo_Volt: ");
printDebugln(Servo_V);
printDebug("Servo_mA: ");
printDebugln(Servo_mA);
printDebug("Arduino_Volt: ");
printDebugln(Arduino_V);
printDebug("Arduino_mA: ");
printDebugln(Arduino_mA);
printDebugln("");
vTaskDelay( 50 / portTICK_PERIOD_MS );
printDebug(RTC.getDay());
printDebug("-");
printDebug(RTC.getMonth());
printDebug("-");
printDebug(RTC.getYear());
printDebug(" ");
printDebug(RTC.getHours());
printDebug(":");
printDebug(RTC.getMinutes());
printDebug(":");
printDebug(RTC.getSeconds());
printDebugln(" ");
vTaskDelay( 50 / portTICK_PERIOD_MS );
/*
printDebug("Time_TFT_loop_AVG: ");
printDebugln(Time_TFT_loop_AVG);
printDebug("Time_Sensors_loop_AVG: ");
printDebugln(Time_Sensors_loop_AVG);
printDebug("Time_IO_loop_AVG: ");
printDebugln(Time_IO_loop_AVG);
printDebug("Time_Counter_loop_AVG: ");
printDebugln(Time_Counter_loop_AVG);
printDebug("Time_FRAM_updater_AVG: ");
printDebugln(Time_FRAM_updater_AVG);
printDebug("Time_Serial_updater_AVG: ");
printDebugln(Time_Serial_updater_AVG);
printDebug("Millis(): ");
printDebugln(millis());
vTaskDelay( 50 / portTICK_PERIOD_MS );
*/
printDebugln("");
printDebug("Free stack ");
printDebug(pcTaskGetName(TFT_loop_Handle));
printDebug(" is : ");
printDebugln(uxTaskGetStackHighWaterMark(TFT_loop_Handle));
printDebugln("");
printDebug("Free stack ");
printDebug(pcTaskGetName(Sensors_loop_Handle));
printDebug(" is : ");
printDebugln(uxTaskGetStackHighWaterMark(Sensors_loop_Handle));
printDebugln("");
printDebug("Free stack ");
printDebug(pcTaskGetName(IO_loop_Handle));
printDebug(" is : ");
printDebugln(uxTaskGetStackHighWaterMark(IO_loop_Handle));
printDebugln("");
printDebug("Free stack ");
printDebug(pcTaskGetName(Counter_loop_Handle));
printDebug(" is : ");
printDebugln(uxTaskGetStackHighWaterMark(Counter_loop_Handle));
printDebugln("");
printDebug("Free stack ");
printDebug(pcTaskGetName(FRAM_updater_Handle));
printDebug(" is : ");
printDebugln(uxTaskGetStackHighWaterMark(FRAM_updater_Handle));
printDebugln("");
printDebug("Free stack ");
printDebug(pcTaskGetName(Serial_updater_Handle));
printDebug(" is : ");
printDebugln(uxTaskGetStackHighWaterMark(Serial_updater_Handle));
printDebugln("");
vTaskDelay( 50 / portTICK_PERIOD_MS );
printDebug("Screen Update behind: ");
printDebugln(millis() - lastScreenUpdate);
printDebug("Sensors Update behind: ");
printDebugln(millis() - lastSensorsUpdate);
printDebug("IO loop Update behind: ");
printDebugln(millis() - lastIOloopUpdate);
printDebug("Counter Loop Update behind: ");
printDebugln(millis() - lastCounterLoopUpdate);
printDebug("FRAM write behind: ");
printDebugln(millis() - lastFRAMwrite);
printDebug("Print Update behind: ");
printDebugln(millis() - lastPrintUpdate);
//FOR PLOTTER MODE
if(PlotterMode){
Serial.print("output_Percentage:");
Serial.print(output_Percentage);
Serial.print(",");
Serial.print("FlowF_Set:");
Serial.print(FlowF_Set);
Serial.print(",");
Serial.print("FlowF_Temp:");
Serial.print(FlowF_Temp);
Serial.print(",");
Serial.print("Kedel_Set:");
Serial.print(Kedel_Set);
Serial.print(",");
Serial.print("Kedel_Temp:");
Serial.print(Kedel_Temp);
Serial.print(",");
Serial.print("FlowR_Temp:");
Serial.print(FlowR_Temp);
Serial.print(",");
Serial.print("Box_Temp:");
Serial.print(Box_Temp);
Serial.print(",");
Serial.print("Blaeser_Output_Procent:");
Serial.println(Blaeser_Output_Procent);
}
//Handle user inputs
if (Serial.available() > 0){
char incomingByte = 0;
incomingByte = Serial.read();
if(!ParameterReception)
{
if(incomingByte == 'p' || incomingByte == 'P')
{//Enable plotter mode
DebugMode = false;
PlotterMode = true;
ParameterReception = false;
}
else if(incomingByte == 'd' || incomingByte == 'D')
{//Bebug mode
DebugMode = true;
PlotterMode = false;
ParameterReception = false;
}
else if(incomingByte == 'o' || incomingByte == 'O')
{//Disable serial print
DebugMode = false;
PlotterMode = false;
ParameterReception = false;
}
else if(incomingByte == 'K' )
{ //Brugeren skal skrive noget lignende "Kp=2.0"
ParameterReception = true;
}
}
if(ParameterReception)
{
if(incomingByte == '\n' || SerielInputBuffer_index > 9)
{
String StringParameter = SerielInputBuffer.substring(0,3);
String StringWithNumber = SerielInputBuffer.substring(3,SerielInputBuffer.length());
float NumberConverted = StringWithNumber.toFloat();
if(NumberConverted == 0 || NumberConverted < 0.0)
{
Serial.println("BAD INPUT VALUE");
}
else if(StringParameter == "Kp=")
{
Kp = NumberConverted;
}
else if(StringParameter == "Ki=")
{
Ki = NumberConverted;
}
else if(StringParameter == "Kd=")
{
Kd = NumberConverted;
}/*
Serial.print("StringParameter :");
Serial.println(StringParameter);
Serial.print("Updated StringWithNumber");
Serial.println(StringWithNumber);*/
myPID.SetTunings(Kp, Ki, Kd);
Serial.print("Updated Kp:");
Serial.println(Kp,3);
Serial.print("Updated Ki:");
Serial.println(Ki,3);
Serial.print("Updated Kd:");
Serial.println(Kd,3);
SerielInputBuffer = "";
SerielInputBuffer_index = 0;
ParameterReception = false;
}
else
{
SerielInputBuffer += incomingByte;
SerielInputBuffer_index++;
}
}
}
lastPrintUpdate = millis();
}
}
}
/*void CycleTime_loop(){
Time_TFT_loop_LAST = Time_TFT_loop - Time_Start;
Time_Sensors_loop_LAST = Time_Sensors_loop - Time_TFT_loop;
Time_IO_loop_LAST = Time_IO_loop - Time_Sensors_loop;
Time_Counter_loop_LAST = Time_Counter_loop - Time_IO_loop;
Time_FRAM_updater_LAST = Time_FRAM_updater - Time_Counter_loop;
Time_Serial_updater_LAST = Time_Serial_updater - Time_FRAM_updater;
Time_TFT_loop_SUM += Time_TFT_loop_LAST;
Time_Sensors_loop_SUM += Time_Sensors_loop_LAST;
Time_IO_loop_SUM += Time_IO_loop_LAST;
Time_Counter_loop_SUM += Time_Counter_loop_LAST;
Time_FRAM_updater_SUM += Time_FRAM_updater_LAST;
Time_Serial_updater_SUM += Time_Serial_updater_LAST;
CycleTime_SUM_RUNS++;
if(CycleTime_SUM_RUNS > 60){
Time_TFT_loop_AVG = Time_TFT_loop_SUM / CycleTime_SUM_RUNS;
Time_Sensors_loop_AVG = Time_Sensors_loop_SUM / CycleTime_SUM_RUNS;
Time_IO_loop_AVG = Time_IO_loop_SUM / CycleTime_SUM_RUNS;
Time_Counter_loop_AVG = Time_Counter_loop_SUM / CycleTime_SUM_RUNS;
Time_FRAM_updater_AVG = Time_FRAM_updater_SUM / CycleTime_SUM_RUNS;
Time_Serial_updater_AVG = Time_Serial_updater_SUM / CycleTime_SUM_RUNS;
Time_TFT_loop_SUM = 0;
Time_Sensors_loop_SUM = 0;
Time_IO_loop_SUM = 0;
Time_Counter_loop_SUM = 0;
Time_FRAM_updater_SUM = 0;
Time_Serial_updater_SUM = 0;
CycleTime_SUM_RUNS = 0;
}
}*/
void loop() {
/*Time_Start = millis();
TFT_loop();
Time_TFT_loop = millis();
Sensors_loop();
Time_Sensors_loop = millis();
IO_loop();
Time_IO_loop = millis();
Counter_loop();
Time_Counter_loop = millis();
FRAM_updater();
Time_FRAM_updater = millis();
Serial_updater();
Time_Serial_updater = millis();
CycleTime_loop();*/
}