![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Rev 1.6 - Sample Period Work in progress
Dependencies: mbed Bitmap N5110 TMP102 Joystick
Diff: main.cpp
- Revision:
- 18:8e025b809dfb
- Parent:
- 17:be8dd797e60b
- Child:
- 19:00cdcf5a5b7a
diff -r be8dd797e60b -r 8e025b809dfb main.cpp --- a/main.cpp Sat Jan 22 13:24:32 2022 +0000 +++ b/main.cpp Sat Jan 22 15:35:53 2022 +0000 @@ -35,6 +35,11 @@ DigitalOut GRN_led(LED_GREEN); DigitalOut BLU_led(LED_BLUE); +DigitalOut Clg_LED(PTA2); +DigitalOut Ready_LED(PTA1); + +DigitalOut Htg_LED(PTC3); + InterruptIn sw2(SW2); // On-board K64F Switches InterruptIn sw3(SW3); InterruptIn R(PTB3); // Right Bumper Button @@ -46,7 +51,7 @@ volatile int g_L_flag = 0; // volatile flag as it will change within the isr volatile int g_A_flag = 0; // g_ in order to show it is a global variable. volatile int g_Y_flag = 0; -//volatile int Setpoint + /*======================= Void Declaration ===================================*/ void error(); // Error Hang Code Function void init_serial(); // Setup serial port Function @@ -60,10 +65,13 @@ void MenuNav(); void Page1(); void Page2(); -void BP(); +void CWtr(); void SP_Array(); +void T_SP_Pg2(); +void HtgClg_Pg2(); + /*======================== Main Function =====================================*/ -int Setpoint[4] = {8,37.65,80,65}; +int Setpoint[4] = {8,37.65,80,24}; int main() { @@ -87,6 +95,11 @@ Y.fall(&Y_isr); Y.mode(PullDown); + Clg_LED = 1; + Ready_LED = 1; + + Htg_LED = 1; + while (1) { //timer.start(); //for(i = 0; i < 10; i++){ @@ -94,8 +107,8 @@ MenuNav(); // Call the info function - Page1(); - Page2(); + //Page1(); + //Page2(); //temp_SP(); @@ -155,9 +168,23 @@ lcd.printString("Louis M",0,2); lcd.printString("18689006",0,3); lcd.printString("Version 1.9.1",0,4); + lcd.refresh(); wait(1); } +void Home() +{ + lcd.clear(); // Clear Screen + serial.printf("Home Menu"); + lcd.printString(" Navigate >",0,0); + lcd.printString(" Use Joystick ",0,1); + lcd.printString(" Welcome ",0,3); // Print Information Screen + lcd.printString(" Main Menu: ",0,4); + lcd.printString(" Y for Info ",0,5); + + lcd.refresh(); + wait(1); +} void Page1() { serial.printf(" Page 1 "); // Debugging Print @@ -194,7 +221,7 @@ g_A_flag = 0; // When the R Flag has been pressed A.rise(&A_isr); serial.printf("A Pressed"); - BP(); + CWtr(); wait(1); } } @@ -232,9 +259,10 @@ //} void MenuNav() { - lcd.clear(); + + lcd.clear(); lcd.refresh(); - + int select = 0; while (1){ @@ -289,22 +317,13 @@ wait(0.1); if (select == 0){ - lcd.clear(); // Clear Screen - serial.printf("WelcomeMENU"); - lcd.printString(" Navigate >",0,0); - lcd.printString(" Welcome ",0,2); // Print Information Screen - lcd.printString(" Main ",0,3); - lcd.printString(" Menu ",0,4); - lcd.printString(" Y for Info ",0,5); - lcd.refresh(); - wait(1); + Home(); } if (g_Y_flag){ // Condition to change over into new loop g_Y_flag = 0; // When the R Flag has been pressed Y.rise(&Y_isr); serial.printf("Y Pressed"); - info(); - + info(); } if (select == 1){ @@ -317,69 +336,89 @@ } } } - -void Menu() -{ - if (g_R_flag){ // Condition to change over into new loop - g_R_flag = 0; // When the R Flag has been pressed - R.rise(&R_isr); - - lcd.clear(); // Clear Screen - serial.printf("Welcome"); - lcd.printString(" Welcome ",0,1); // Print Information Screen - lcd.printString("Main Menu",0,3); - lcd.printString("Page Down",0,5); - lcd.refresh(); - wait(1); -} -} -void BP() +void CWtr() { while(1){ - float BP_SP = Setpoint[0]; + float CWtr_SP = Setpoint[3]; + //serial.printf("SP = %.2f \n",CWtr_SP); float T = tmp102.get_temperature(); // Reading Temperature as a floating variable - serial.printf("SETPOINT = ",Setpoint[1]); - if (BP_SP-- <= T <= BP_SP++){ - - serial.printf("SP = %.2f \n",BP_SP); + serial.printf("SETPOINT = ",CWtr_SP); + if (CWtr_SP-1 > T || T > CWtr_SP+1){ + + HtgClg_Pg2(); lcd.clear(); - char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters) - int length = sprintf(buffer,"SP=%.2f",BP_SP); // print the temperature from the float variable T - if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) - lcd.printString(buffer,0,0); // display on screen - serial.printf("T = %f C\n",Setpoint[0]); - //lcd.printString("Temperature",0,0); // Can also pre-determine the co-ordinates of the ',0,0' (must be less than 84 pixels to fit on display) - - length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T - if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) - lcd.printString(buffer,0,1); // display on screen - serial.printf("T = %f C\n",T); // Printing the Temperature over Serial Port + T_SP_Pg2(); + lcd.printString(" Adjusting ",0,2); // Print Information Screen + lcd.printString(" Water Temp ",0,3); + lcd.printString(" Please Wait! ",4,4); + + lcd.refresh(); + wait(1); + } + else if (CWtr_SP-1 <= T <= CWtr_SP+1){ + HtgClg_Pg2(); + lcd.clear(); + T_SP_Pg2(); lcd.printString(" COLD ",0,2); // Print Information Screen lcd.printString("Drinking Water",0,3); lcd.printString(" Ready! ",4,4); + + Ready_LED = 0; + lcd.refresh(); + Ready_LED = 0; wait(1); - else if - if (g_R_flag){ // Condition to change over into new loop + } + + if (g_R_flag){ // Condition to change over into new loop g_R_flag = 0; // When the R Flag has been pressed R.rise(&R_isr); serial.printf("Home Pressed"); + + Clg_LED = 1; + Htg_LED = 1; + Ready_LED = 1; + MenuNav(); wait(1); - } } - } } -void T_SP_Pg2(); + +void T_SP_Pg2() +{ + float T = tmp102.get_temperature(); + float CWtr_SP = Setpoint[3]; + char buffer[14]; + + int length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T + if (length <= 14); + lcd.printString(buffer,18,0); + serial.printf(" T = %f C\n",T); + + length = sprintf(buffer,"SP=%.2f 'C",CWtr_SP); // print the temperature from the float variable T + if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) + lcd.printString(buffer,13,1); // display on screen + serial.printf(" T = %f C\n",CWtr_SP); +} +void HtgClg_Pg2() { - int length = sprintf(buffer,"SP=%.2f",BP_SP); // print the temperature from the float variable T - if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) - lcd.printString(buffer,0,0); // display on screen - serial.printf("T = %f C\n",Setpoint[0]); - //lcd.printString("Temperature",0,0); // Can also pre-determine the co-ordinates of the ',0,0' (must be less than 84 pixels to fit on display) - - length = sprintf(buffer,"T=%.2F 'C",T); // print the temperature from the float variable T - if (length <= 14) + float T = tmp102.get_temperature(); + float CWtr_SP = Setpoint[3]; + if (T > CWtr_SP+1){ + Clg_LED = 0; + Htg_LED = 1; + Ready_LED = 1; + } + else if (T < CWtr_SP-1){ + Clg_LED = 1; + Htg_LED = 0; + Ready_LED = 1; + } + else { + Clg_LED = 1; + Htg_LED = 1; + + } } \ No newline at end of file