Since I will be busy today, I am posting the initial part of the code to help you in assisting me.
float Irms, flow[3], Pdisch, DpFilter, Pinlet, lampCurrent,auxVol, totalLiters, rawDp_float[3], flapstate_float;
bool flapstate;
char *myVarName[] = {"IRMS", "Flow[1]", "Pdisch", "DpFilter", "Pinlet", "lampCurr", "rawDp[1]", "flap_flo", "auxVol", "flow[2]", "totalLit", "rawDp[2]" };
#include <TFT_eSPI.h> // Hardware-specific library
// In the TFT_ESPI user_setup.h file
// be sure to comment OUT the line for TFT_CS // <======== BE SURE TO DO THIS EVERYTIME A NEW COMPUTER IS USED ==??? Not found in Dec 2022
// //#define TFT_CS 21 // Chip select control pin // OR the library is Re-installed
//------EDIT THIS LINE IN USER_SETUP_SELECT.h--------
// #include <User_Setups/Setup42_ILI9341_ESP32.h> // Setup file for ESP32 and SPI ILI9341 240x320 //<===============This is my setup===================
//
//----- Using faster Graphic Library
TFT_eSPI tft = TFT_eSPI(); // Invoke TFT custom library
// *************My setup for Harware SPI for ILI9341***************
// The pins used by the TFT display are defined in the user_setup.h file
// ####### DO NOT ERASE THIS #######
// TFT_MISO 19
// TFT_MOSI 23
// TFT_SCLK 18
// TFT_CS 15
// TFT_DC 2 // Data Command control pin
// TFT_RST 4 // Reset pin (could connect to RST pin)
// Define variables used to input Data
int myIndex = 0;
float inputValue = 0.0;
//--------------------------------------------------------------------------
// Example 5 - Receive with start- and end-markers combined with parsing
//-----------------------------------------------------------------------------
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars]; // temporary array for use when parsing
// variables to hold the parsed data
char messageFromPC[numChars] = {0};
int integerFromPC = 0;
float floatFromPC = 0.0;
boolean newData1 = false;
//------Define Pin numbers for buttons & LEDs
const int pump_On_Pin = 26;
const int alarm_On_Pin = 12;
const int alarm_Toggle_Button_Pin = 13;
const int ack_Alarm_Button_Pin = 33;
const int buzzerPin = 25;
const int fault_Led_Pin = 27;
const int warning_Led_Pin = 14;
// Define Variables used to test alarms/ack functions
bool faultStatus = LOW;
bool warningStatus = LOW;
bool ackAlarmStatus = LOW;
bool delayRunning = LOW;
bool pump_State = LOW;
bool last_Pump_State = LOW;
bool flowDelay = LOW;
bool clearDataFlag = true;
bool cisternaRxLoss = false;
bool caixaRxLoss = false;
bool buzzer_ON_OFF_Toggle = LOW; //is buzzer ON or OFF
bool buzzer_Status = LOW;
bool levelWarningStatus = LOW;
int rawDp[3] = {0, 0 , 0};
int rawDpMin = 32;
int rawDpMax[3] = {0, 243 , 187}; // values changed in rev 2_A
int levelDp[3] = {0, 0 , 0};
int levelDpLow = 30; // critical level in %
int levelDpMin = 20; // minimal level in %
int levelDpWarning = 50; // warning leval in %
float flowMin[3] = { 0.0 , 1.3 , 10.0 };
//----Toggle button & Misc stuff----
int buzzerState=0;
int alarm_Button_New;
int alarm_Button_Old=1;
//???int ack_Button_New;
//???int ack_Button_Old=1;
int dt=500;
bool ack_ID[7] = {0,0,0,0,0,0,0};
bool fault_ID[7] = {0,0,0,0,0,0,0};
bool fault_ID_Old[7] = {0,0,0,0,0,0,0};
// unsigned long ack_ID_mil[7] = {0,0,0,0,0,0,0}; // Jan2023
unsigned long time_between_failures = 60000; //3600000; <===== ATTENTION VALUE CHANGED TO CHECK LOGIC!!!!!!
unsigned long fault_ID_mil[7];
unsigned long fault_ID_mil_Old[7] = { 0, 0, 0, 0, 0, 0, 0 };
int i= 1;
int x = 1;
unsigned long t1;
unsigned long t2;
//============
void setup() { //----------------------------------------------------- SETUP BEGINGS HERE -----------------------------------------------------------------------
Serial.begin(9600);
// ----define Led pins as outputs
pinMode(alarm_On_Pin, OUTPUT);
pinMode(pump_On_Pin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(alarm_Toggle_Button_Pin, INPUT_PULLUP);
pinMode(ack_Alarm_Button_Pin, INPUT_PULLUP);
pinMode(warning_Led_Pin, OUTPUT);
pinMode(fault_Led_Pin, OUTPUT);
//-----Start TFT, set rotation and background color------
tft.init();
tft.setRotation(0);
tft.setTextSize(2);
//------- Initialize display
tft.setCursor(0, 0);
tft.setTextColor(ILI9341_YELLOW);
tft.println("ACK ALARM TEST");
tft.println("Rev0 31/12/2022");
delay(2000);
Serial.println("This sketch expects 2 pieces of data: an integer (the index) and a floating point value (the value of the variable)");
Serial.println("Enter data in this style < 1, 24.7> ");
Serial.println();
// test: Print variable names in serial port
for (int k = 0; k<12; k++) { // <====ATTENTION!!! First index is ZERO
Serial.println(myVarName[k]);
}
// --------- Define a "NORMAL" Value for the variable being analyzed----------- <============= REMOVE AFTER TESTING!!!!!!!
flow[1] = 5.0;
rawDp[1] = 218; // ======> level aprox 90%
// -------Calculate output variables from raw data ---------
levelDp[1] = map(rawDp[1], rawDpMin, rawDpMax[1], 0, 100);
}
//----------------------------------------------------------------END OF SETUP--------------------------------
void loop() { //--------------------------------------------------------LOOP BEGINS HERE --------------------------------------------------------------------------------
// Read Serial data
recvWithStartEndMarkers();
if (newData1 == true) {
strcpy(tempChars, receivedChars);
// this temporary copy is necessary to protect the original data
// because strtok() used in parseData() replaces the commas with \0
parseData();
showParsedData();
assignValue();
newData1 = false;
}
// Check if there are faults
fake_display_faults();
// Define if buzzer is ON or Off
buzzer_On_Off_Toggle();
delay(500);
// Check if the buzzer should be turned on
check_Alarm_Status();
// If alarm pin is HIGH, beep buzzer
beep_Buzzer();
// Check if Alarm was ackoledged
ack_Alarm();
// Reset Alarm times
// reset_Alarms();
}
//----------------------------------------------------------LOOP ENDS HERE-----------------------------------------------------