Rev 1.6 - Sample Period Work in progress

Dependencies:   mbed Bitmap N5110 TMP102 Joystick

Revision:
17:be8dd797e60b
Parent:
16:648f9012c47a
Child:
18:8e025b809dfb
--- a/main.cpp	Sat Jan 22 11:49:28 2022 +0000
+++ b/main.cpp	Sat Jan 22 13:24:32 2022 +0000
@@ -63,6 +63,8 @@
 void BP();
 void SP_Array();
 /*======================== Main Function =====================================*/
+int Setpoint[4] = {8,37.65,80,65};
+
 int main()
 {
     
@@ -94,7 +96,7 @@
         MenuNav();                                         // Call the info function                                              
         Page1();
         Page2();
-        temp_SP();
+        //temp_SP();
         
                                                                 
     }
@@ -167,27 +169,30 @@
            
         lcd.refresh();
         wait(1);
+        //while (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");
                 temp_SP();
-                }
+                wait(1);
+                }//}
+                
 }
 void Page2()
 {        
         serial.printf(" Page 2 ");  // Debugging Print
         lcd.clear();                                   // Clear Screen
-        lcd.printString("<   Page 2    ",0,0);              // Print Information Screen
-        lcd.printString("Outside Air",0,1);
-        lcd.printString(" Recommends ",0,2);
+        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_R_flag){                               // Condition to change over into new loop
-                g_R_flag = 0;                                   // When the R Flag has been pressed
-                R.rise(&R_isr);
+         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");
                 BP();
                 wait(1);
@@ -195,14 +200,13 @@
 }
 void temp_SP()
 {
-        
+        //while(1){
         float T = tmp102.get_temperature();             // Reading Temperature as a floating variable
         float Set = SP * 100;                           // Reading Potentiometer as a floating variable. Multiplied by 100 to give larger range        
         
         lcd.clear();                                    // clearing the LCD buffer at the begining of the loop        
         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)            
         char buffer[14];                                // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters)
-        Direction d = Joystick.get_direction();
                                                                   
         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)                                                                  
@@ -215,15 +219,17 @@
         serial.printf("   SP = %f",  Set);              // 
         lcd.refresh();
                 wait(1);
+        //while (1){
         if (Set < T){                                // Condition to change over into new loop
             lcd.clear();                                    // clearing the LCD buffer at the begining of the loop
             lcd.printString("Over Heating",3,2);            // Print New Message
             serial.printf("OverTemp");                      // Debugging Print   
         lcd.refresh();
                 wait(1);
+        //}
         }
-        
-}    
+}       
+//}    
 void MenuNav()
 { 
         lcd.clear();
@@ -235,8 +241,7 @@
     
     //serial.printf("Direction = %i ",d);
     Direction d = Joystick.get_direction();
-        
-    //while (1) {
+
         switch(select) {
             case 0:
                 switch(d) {
@@ -299,16 +304,16 @@
                 Y.rise(&Y_isr);
                 serial.printf("Y Pressed");
                 info();
+                
                 }
             
             if (select == 1){
-                Page1();
-            
+                Page1();                            
                 }
             
             if (select == 2){
                 Page2();
-           
+                
                 }
 }
 }      
@@ -330,28 +335,51 @@
 }
 void BP()
 {
-    int Setpoint[4] = {8,37.65,80,65};
-        float BP_SP = Setpoint[0];
+    while(1){
+    float BP_SP = Setpoint[0];
     float T = tmp102.get_temperature();             // Reading Temperature as a floating variable
     serial.printf("SETPOINT = ",Setpoint[1]);
-    if (T > Setpoint[0]){
+    if (BP_SP-- <= T <= BP_SP++){
+                
                 serial.printf("SP = %.2f \n",BP_SP);
                 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,1);                // display on screen
+                lcd.printString(buffer,0,0);                // display on screen
                 serial.printf("T = %f C\n",Setpoint[0]);
-                lcd.printString("   Wear   ",0,2);              // Print Information Screen
-                lcd.printString("   Warm   ",0,3);
-                lcd.printString(" Clothing ",0,4);    
+                //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
+
+                lcd.printString("     COLD     ",0,2);              // Print Information Screen
+                lcd.printString("Drinking Water",0,3);
+                lcd.printString("    Ready!    ",4,4);    
                 lcd.refresh();
                 wait(1);  
+        else if 
+                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");
+                MenuNav();
+                wait(1);
+                } 
                 }
 
 }
-void SP_Array()
+}
+void T_SP_Pg2();
 {
-    int Setpoint[4] = {8,37.65,80,65};
-
+        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)
 }
\ No newline at end of file