![](/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:
- 21:bf02fb9876b3
- Parent:
- 20:3bc5958190cd
- Child:
- 22:ef63c41689c2
--- a/main.cpp Sat Jan 22 19:11:39 2022 +0000 +++ b/main.cpp Sat Jan 22 19:43:49 2022 +0000 @@ -35,6 +35,7 @@ DigitalOut Clg_LED(PTA2); // Green LED on PCB for Cooling DigitalOut Ready_LED(PTA1); // Green LED on PCB for when water is ready DigitalOut Htg_LED(PTC3); // Red LED on PCB for Cooling +DigitalOut Boil_LED(PTD3); InterruptIn sw2(SW2); // On-board K64F Switches InterruptIn sw3(SW3); @@ -79,6 +80,9 @@ void T_SP_Pg2(); void HtgClg_Pg2(); +void BWtr(); // Page 2 - Mode Functions +void T_SP_Pg3(); +void HtgClg_Pg3(); /*======================== Main Function =====================================*/ @@ -109,6 +113,7 @@ Clg_LED = 1; // Disabling the LED's Ready_LED = 1; Htg_LED = 1; + Boil_LED = 1; while (1) { @@ -204,6 +209,7 @@ lcd.refresh(); wait(1); + if (g_A_flag){ // Condition to change over into new loop g_A_flag = 0; // When the R Flag has been pressed A.rise(&A_isr); @@ -216,13 +222,14 @@ { serial.printf(" Page 2 "); // Debugging Print lcd.clear(); // Clear Screen - lcd.printString("< Page 2",0,0); // Print Information Screen + lcd.printString("< Page 2 >",0,0); // Print Information Screen lcd.printString(" MODE ",0,1); lcd.printString("Drinking Water",0,2); lcd.printString(" Press A ",0,3); lcd.refresh(); wait(1); + if (g_A_flag){ // Condition to change over into new loop g_A_flag = 0; // When the R Flag has been pressed A.rise(&A_isr); @@ -231,7 +238,26 @@ wait(1); } } - +void Page3() +{ + serial.printf(" Page 3 "); // Debugging Print + lcd.clear(); // Clear Screen + lcd.printString("< Page 3",0,0); // Print Information Screen + lcd.printString(" MODE ",0,1); + lcd.printString("Boiling Water",0,2); + lcd.printString(" Press A ",0,3); + + lcd.refresh(); + wait(1); + + if (g_A_flag){ // Condition to change over into new loop + g_A_flag = 0; // When the R Flag has been pressed + A.rise(&A_isr); + serial.printf("A Pressed"); + BWtr(); + wait(1); + } +} void MenuNav() { @@ -284,11 +310,25 @@ break; // Break out from Loop case E: // If the direction is E (Right) carry out Case E wait(0.5); // Delay added to allow for joystick movement - Mode = 2; // Remain in Mode 2 - Prevents idol cycling through the switch + Mode = 3; // Remain in Mode 2 - Prevents idol cycling through the switch + //serial.printf("RIGHT.2"); // Debugging Print + break; // Break out from Loop + } + case 3: // Main Initial Case instance - When at Page 1 + switch(d) { // Looking at the Joystick Direction for internal switch + case W: // If the direction is W (Left) carry out Case W + wait(0.5); // Delay added to allow for joystick movement + Mode = 2; // Return to Mode 1 + //serial.printf("LEFT.2"); // Debugging Print + break; // Break out from Loop + case E: // If the direction is E (Right) carry out Case E + wait(0.5); // Delay added to allow for joystick movement + Mode = 3; // Remain in Mode 2 - Prevents idol cycling through the switch //serial.printf("RIGHT.2"); // Debugging Print break; // Break out from Loop } break; // Break out from Loop into Main Switch + } wait(0.5); @@ -301,6 +341,9 @@ else if (Mode == 2){ Page2(); } + else if (Mode == 3){ + Page3(); + } } } void WWtr() @@ -407,6 +450,59 @@ } } } +void BWtr() +{ + /** Warm Washing Water Mode + * Using Parameters for Safe Washing Water Temperature + */ + while(1){ + + float T = tmp102.get_temperature(); // Reading Temperature as a floating variable + float SP = Setpoint[2]; // Reading the Setpoint from the Array + //serial.printf("SP = %.2f \n",CWtr_SP); // Debugging Print + //serial.printf("SETPOINT = ",CWtr_SP); // Debugging Print + if (SP-1 > T || T > SP+1){ // If the Temperature is not within the Tolerance + + HtgClg_Pg3(); // Heating Cooling Control Function + lcd.clear(); // Clear LCD Screen + T_SP_Pg3(); // Print Modes Temperature & Setpoint info + lcd.printString(" Adjusting ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) + lcd.printString(" Water Temp ",0,3); + lcd.printString(" Please Wait! ",4,4); + + lcd.refresh(); // Refresh & Display printed strings to LCD + wait(1); + } + + else if (SP-1 <= T <= SP+1){ // If the Temperature is within the Tolerance + + HtgClg_Pg3(); // Heating Cooling Control Function + lcd.clear(); // Clear LCD Screen + T_SP_Pg3(); // Print Modes Temperature & Setpoint info + lcd.printString(" Boiling ",0,2); // Display string on screen, Determine Co-ordinates (..,Column, Row) + lcd.printString("Boiling Water",0,3); + lcd.printString(" Ready! ",4,4); + lcd.printString(" WARNING HOT! ",0,5); + lcd.refresh(); // Refresh & Display printed strings to LCD + Ready_LED = 0; + Boil_LED = 0; // Enable the Boiling LED + wait(1); + } + + if (g_R_flag){ // Condition to change over into new loop + g_R_flag = 0; // When the Button has been pressed + R.rise(&R_isr); // Button Rising edge + //serial.printf("Home Pressed"); // Debugging Print + + Clg_LED = 1; // Disable the LED's for next Mode + Htg_LED = 1; + Ready_LED = 1; + + MenuNav(); // Return to Navigation Menu + wait(1); + } + } +} void T_SP_Pg1() { /** Mode Select @@ -501,4 +597,51 @@ Clg_LED = 1; // Disable Heating & cooling LED's Htg_LED = 1; } +} +void T_SP_Pg3() +{ + /** Mode Select + * When a new mode is selected the LCD screen will update in order + * to assist the user with the water temperature in order to provide + * Assistance, Safety and Comfort + */ + float T = tmp102.get_temperature(); // Reading Temperature as a floating variable + float SP_3 = Setpoint[2]; // Reading the Mode Setpoint from the Array + char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters) + + int 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,18,0); // Display string on screen, Determine Co-ordinates (..,Column, Row) + //serial.printf(" T = %f C\n",T); // Debugging Print + + length = sprintf(buffer,"SP=%.2f 'C",SP_3); // print the Setpoint from the Setpoint Variable + if (length <= 14) // Ensuring string will fit on the screen (Printing at x=0) + lcd.printString(buffer,13,1); // Display string on screen, Determine Co-ordinates (..,Column, Row) + //serial.printf(" T = %f C\n",SP_3); // Debugging Print +} +void HtgClg_Pg3() +{ + /** Water Temperature Control + * Control Mode which enables LED's if the temperature goes outside + * of the +/- Setpoint Tolerance. + * Dependant on the Mode Application will depend on which setpoint is + * selected from the Setpoint Array + */ + float T = tmp102.get_temperature(); // Reading Temperature as a floating variable + float SP_3 = Setpoint[2]; // Reading the Mode Setpoint from the Array + if (T > SP_3+1){ // If Temp is above the setpoint + Clg_LED = 0; // Enable the Cooling LED + Htg_LED = 1; // Disable other LED's + Ready_LED = 1; + serial.printf("cooling"); + } + else if (T < SP_3-1){ // If Temp is below the setpoint + Htg_LED = 0; // Enable the Heating LED + Clg_LED = 1; // Disable other LED's + Ready_LED = 1; + } + else { // If none of the conditions are satisfied + Clg_LED = 1; // Disable Heating & cooling LED's + Htg_LED = 1; + } } \ No newline at end of file