![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
legionella detector
Dependencies: mbed
Diff: main.cpp
- Revision:
- 3:eaa6fbb8fd87
- Parent:
- 2:9d6daa8a091c
- Child:
- 4:b82f09e597ec
--- a/main.cpp Tue Aug 23 09:55:54 2022 +0000 +++ b/main.cpp Tue Aug 23 12:49:09 2022 +0000 @@ -81,6 +81,17 @@ void get_temp(); void CustHi_SP(); void CustLo_SP(); +void ShowSP(); + +//State structure +struct State { + //Output Setpoint + int output; + //Time delay while in state + float time; + //Next states array and length + int nextState[9]; +}; @@ -106,7 +117,7 @@ lcd.init(); Joystick.init(); - lcd.setContrast(0.5); + lcd.setContrast(1); lcd.setBrightness(0.5); startup(); @@ -159,6 +170,9 @@ { lcd.printString("Lewis Cameron",0,0); lcd.printString("18689002",0,1); + lcd.printString("Legionella",0,2); + lcd.printString("Sensor",0,3); + lcd.printString("w/ Custom SP",0,4); pc.printf("startup"); lcd.refresh(); wait(5); @@ -182,28 +196,33 @@ lcd.clear(); - lcd.printString("CWS",20,0); - lcd.printString("Temp is",0,2); + lcd.printString("CWS",30,0); + lcd.printString("Temp =",0,1); get_temp(); - lcd.printString("Press Back To Go Home",0,5); + lcd.printString("Back = Home",0,5); + pc.printf("CWS"); if (temp >= CwsHiSP){ - lcd.printString("Water Temp Too High",0,3); - lcd.printString("Legionella Warning",0,4); + lcd.printString("CWS Temp High",0,2); + lcd.printString("Legionella",0,3); + lcd.printString("Warning",0,4); led_red1 = 0; + pc.printf("CWS High Temp"); } else if (temp < CwsHiSP){ - lcd.printString("Water Temp OK",0,3); - lcd.printString("No Danger Of Legionella",0,4); + lcd.printString("Temp OK",0,2); + lcd.printString("No Danger",0,3); + lcd.printString("Of Legionella",0,4); led_red1 = 1; + pc.printf("CWS Temp OK"); } if (button_back_flag) { button_back_flag = 0; page = 0; } - + lcd.refresh(); } break; @@ -214,27 +233,30 @@ float temp = tmp.get_temperature(); lcd.clear(); - lcd.printString("HWS",20,0); - lcd.printString("Temp is",0,2); + lcd.printString("HWS",30,0); + lcd.printString("Temp =",0,1); get_temp(); - lcd.printString("Press Back To Go Home",0,5); + lcd.printString("Back = Home",0,5); - if (HwsLoLimSP < temp < HwsKaSP){ - lcd.printString("Temperature Raised",0,3); - lcd.printString("Killing Legionella",0,4); + if (HwsLoLimSP < temp & temp < HwsKaSP){ + lcd.printString("Temp Raised",0,2); + lcd.printString("Killing",0,3); + lcd.printString("Legionella",0,4); led_green1 = 0; } else if (temp >= HwsKaSP){ - lcd.printString("Temperature Raised",0,3); - lcd.printString("All Legionella Killed",0,4); + lcd.printString("Temp Raised",0,2); + lcd.printString("No Danger",0,3); + lcd.printString("Of Legionella",0,4); led_green1 = 0; led_green2 = 0; } else if (temp < HwsLoLimSP){ - lcd.printString("Temperature Low",0,3); - lcd.printString("Legionella Warning",0,4); + lcd.printString("Temp Low",0,2); + lcd.printString("Legionella",0,3); + lcd.printString("Warning",0,4); led_red1 = 0; } @@ -243,6 +265,8 @@ page = 0; } + lcd.refresh(); + } @@ -253,19 +277,38 @@ { init_pcb(); + float temp = tmp.get_temperature(); + lcd.clear(); - lcd.printString("Custom SP",20,0); - lcd.printString("Temp is",0,2); + lcd.printString("Custom SP",15,0); + lcd.printString("Temp =",0,1); get_temp(); CustHi_SP(); CustLo_SP(); - lcd.printString("Press Back To Go Home",0,5); + ShowSP(); + lcd.printString("Back = Home",0,5); + + if (CustomLoSP < temp & temp < CustomHiSP){ + lcd.printString("Temp In Range",0,4); + led_green1 = 0; + } + + else if (temp > CustomHiSP){ + lcd.printString("High Temp",0,4); + led_red1 = 0; + } + + else if (temp < CustomLoSP){ + lcd.printString("Low Temp",0,4); + led_red2 = 0; + } if (button_back_flag) { button_back_flag = 0; page = 0; } + lcd.refresh(); } @@ -275,11 +318,13 @@ { init_pcb(); lcd.clear(); - lcd.printString("Info",20,0); - lcd.printString("Legionella Detector",0,1); - lcd.printString("Lewis Cameron",0,2); - lcd.printString("18689002",0,3); - lcd.printString("Press Back To Go Home",0,4); + lcd.printString("Info",26,0); + lcd.printString("Legionella",0,1); + lcd.printString("Detector",0,2); + lcd.printString("Lewis Cameron",0,3); + lcd.printString("18689002",0,4); + lcd.printString("Back = Home",0,5); + lcd.refresh(); if (button_back_flag) { button_back_flag = 0; @@ -296,7 +341,7 @@ init_pcb(); lcd.clear(); - lcd.printString("Main Menu",0,0); + lcd.printString("Main Menu",15,0); lcd.printString("A = Cold Water",0,1); lcd.printString("B = Hot Water",0,2); lcd.printString("X = Custom SP",0,3); @@ -306,21 +351,25 @@ if (button_a_flag) { button_a_flag = 0; page = 1; + pc.printf("A Pressed"); } if (button_b_flag) { button_b_flag = 0; page = 2; + pc.printf("B Pressed"); } if (button_x_flag) { button_x_flag = 0; page = 3; + pc.printf("X Pressed"); } if (button_y_flag) { button_y_flag = 0; page = 4; + pc.printf("Y Pressed"); } } @@ -385,7 +434,7 @@ int length = sprintf(buffer,"%.2f C",temp); //pc.printf("temp = %f K\n",temp); if (length <=14) - lcd.printString(buffer,20,2); + lcd.printString(buffer,38,1); } @@ -394,23 +443,17 @@ Direction d = Joystick.get_direction(); - if (d = W) { - CustomHiSPChange = CustomHiSP - 1; + if (d == W) { + pc.printf("Joystick Left"); + CustomHiSP = CustomHiSP - 1; wait(0.5); - CustomHiSPChange = CustomHiSP; } - if (d = E) { - CustomHiSPChange = CustomHiSP + 1; + if (d == E) { + pc.printf("Joystick Right"); + CustomHiSP = CustomHiSP + 1; wait(0.5); - CustomHiSPChange = CustomHiSP; - char buffer[14]; - int length = sprintf(buffer,"HiLimSP=%.2iC",CustomHiSP); - - if (length <= 14); { - lcd.printString(buffer,0,3); - } } } @@ -418,25 +461,36 @@ { if (button_left_flag) { button_left_flag = 0; - CustomLoSPChange = CustomLoSP - 1; + pc.printf("Left pressed"); + CustomLoSP = CustomLoSP - 1; wait(0.5); - CustomLoSPChange = CustomLoSP; } if (button_right_flag) { button_right_flag = 0; - CustomLoSPChange = CustomLoSP + 1; + pc.printf("Right pressed"); + CustomLoSP = CustomLoSP + 1; wait(0.5); - CustomLoSPChange = CustomLoSP; } - char buffer[14]; +} + +void ShowSP() +{ + char buffer[14]; int length = sprintf(buffer,"LoLimSP=%.2iC",CustomLoSP); if (length <= 14); { - lcd.printString(buffer,0,4); + lcd.printString(buffer,0,3); + } + + length = sprintf(buffer,"HiLimSP=%.2iC",CustomHiSP); + + if (length <= 14); { + lcd.printString(buffer,0,2); } } + void TMP102::error() {