Rev 1.6 - Sample Period Work in progress

Dependencies:   mbed Bitmap N5110 TMP102 Joystick

Revision:
20:3bc5958190cd
Parent:
19:00cdcf5a5b7a
Child:
21:bf02fb9876b3
--- a/main.cpp	Sat Jan 22 16:19:27 2022 +0000
+++ b/main.cpp	Sat Jan 22 19:11:39 2022 +0000
@@ -11,11 +11,11 @@
 ======================== Library Imports =======================================
 Importing the Header Files from the Class Libraries into the main.cpp
 */
-#include "mbed.h"                               // Mbed OS Library
-#include "TMP102.h"                             // TMP102 Header File
-#include "N5110.h"                              // N5110 Header File 
-#include "Bitmap.h"                             // Bitmap Header File 
-#include "Joystick.h"                           // Joystick Header File
+#include "mbed.h"                              // Mbed OS Library
+#include "TMP102.h"                            // TMP102 Header File
+#include "N5110.h"                             // N5110 Header File 
+#include "Bitmap.h"                            // Bitmap Header File 
+#include "Joystick.h"                          // Joystick Header File
 
 /*
 ========================== Vairable Setup ======================================
@@ -25,53 +25,64 @@
 TMP102 tmp102(I2C_SDA,I2C_SCL);                // Create TMP102 object
 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);     // Create lcd objec
 Serial serial(USBTX,USBRX);                    // CoolTerm TX, RX Comms Setup for Debug
-AnalogIn SP(PTB2);                             // Potentiometer for Setpoint
+AnalogIn SetP(PTB2);                             // Potentiometer for Setpoint
 Joystick Joystick(PTB10,PTB11,PTC16);          // Create Joystick (PTB10 = Up/Down) (PTB11 = L/R) (PTB16 = Button)
 
-//Timer timer();                                 // USE FOR LOGGING BETWEEN 0-10s
-Ticker joystickDelay;
-
 DigitalOut RED_led(LED_RED);                   // On-board K64F LED'S
 DigitalOut GRN_led(LED_GREEN);
 DigitalOut BLU_led(LED_BLUE);
 
-DigitalOut Clg_LED(PTA2);
-DigitalOut Ready_LED(PTA1);
-
-DigitalOut Htg_LED(PTC3);
+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
 
 InterruptIn sw2(SW2);                          // On-board K64F Switches
 InterruptIn sw3(SW3);
-InterruptIn R(PTB3);                         // Right Bumper Button
-InterruptIn L(PTB18);                        // Left Bumper Button
-InterruptIn A(PTB9);                         // Right Bumper Button
-InterruptIn Y(PTC12);                        // Left Bumper Button
+InterruptIn R(PTB3);                           // Right Bumper Button
+InterruptIn L(PTB18);                          // Left Bumper Button
+InterruptIn A(PTB9);                           // A button Button
+InterruptIn Y(PTC12);                          // Y Button Button
+
+                                               // Interrupt Services volatile flag which will change within the isr
 
-volatile int g_R_flag = 0;                    // g_ in order to show it is a global variable. 
-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 g_R_flag = 0;                     // g_ in order to show it is a global variable. 
+volatile int g_L_flag = 0;                    
+volatile int g_A_flag = 0;                    
+volatile int g_Y_flag = 0;                    
 
-/*======================= Void Declaration ===================================*/
+/*
+========================= Void Declaration =====================================
+Functions to be called throughout code in order to improve readability
+*/
 void error();                                  // Error Hang Code Function
 void init_serial();                            // Setup serial port Function
 void init_K64F();                              // K64F Disabling Onboard Components Function
-void R_isr();
+
+void R_isr();                                  // Interrupt Voids
 void L_isr();
 void A_isr();
 void Y_isr();
-void info();
-void temp_SP();
-void MenuNav();
+
+                                                // Display Screen Voids used in the Menu
+void info();                                   
 void Page1();
 void Page2();
-void CWtr();
-void SP_Array();
-void T_SP_Pg2();
+void Home();
+
+void MenuNav();                                // Menu Navigation using the Joystick to move Left & Right
+
+void WWtr();                                   // Page 1 - Mode Functions
+void T_SP_Pg1();                               
+void HtgClg_Pg1();
+
+void CWtr();                                   // Page 2 - Mode Functions
+void T_SP_Pg2();                               
 void HtgClg_Pg2();
 
+
 /*======================== Main Function =====================================*/
-int Setpoint[4] = {8,37.65,80,24};
+
+int Setpoint[4] = {8,37,80,24};              // Setpoint Array to be used dependant on Mode Selected
 
 int main()
 {
@@ -95,23 +106,13 @@
     Y.fall(&Y_isr);
     Y.mode(PullDown);
     
-    Clg_LED = 1;
+    Clg_LED = 1;                                // Disabling the LED's
     Ready_LED = 1;
-    
     Htg_LED = 1;
     
     while (1) {        
-        //timer.start(); 
-        //for(i = 0; i < 10; i++){
-        // read temperature and print over serial port
-        
-        
-        MenuNav();                                         // Call the info function                                              
-        //Page1();
-        //Page2();
-        //temp_SP();
-        
-                                                                
+               
+        MenuNav();                                                                                                                                                      
     }
 
 }
@@ -150,24 +151,24 @@
 {
     g_L_flag = 1;                       // set flag in ISR
 }
-void A_isr()                            // Left Bumper Interrupt Service     
+void A_isr()                            // A Button Interrupt Service     
 {
     g_A_flag = 1;                       // set flag in ISR
 }
-void Y_isr()                            // Left Bumper Interrupt Service     
+void Y_isr()                            // Y Button Interrupt Service     
 {
     g_Y_flag = 1;                       // set flag in ISR
 }
 void info()
 {
 
-        serial.printf(" Information Page Selected ");  // Debugging Print
-        lcd.clear();                                   // Clear Screen
-        lcd.printString("Info Page",0,0);              // Print Information Screen
-        lcd.printString("Author:",0,1);
-        lcd.printString("Louis M",0,2);
-        lcd.printString("18689006",0,3);
-        lcd.printString("Version 1.9.1",0,4);   
+        serial.printf(" Information Page Selected ");    // Debugging Print
+        lcd.clear();                                     // Clear Screen
+        lcd.printString("Info Page V",0,0);                // Print Information Screen
+        lcd.printString("Author: LM",0,1);
+        lcd.printString("18689006",0,2);
+        lcd.printString("R = Home",0,3);
+        lcd.printString("A = Select",0,4);   
         
         lcd.refresh();
         wait(1);
@@ -184,27 +185,32 @@
                 
                 lcd.refresh();
                 wait(1);
+                
+                if (g_Y_flag){                               // Condition to change over into new loop
+                    g_Y_flag = 0;                            // When the Button has been pressed
+                    Y.rise(&Y_isr);
+                    serial.printf("Y Pressed");
+                    info();                
+                        }
 }
 void Page1()
-{
+{        
         serial.printf(" Page 1 ");  // Debugging Print
         lcd.clear();                                   // Clear Screen
         lcd.printString("<   Page 1   >",0,0);              // Print Information Screen
-        lcd.printString("Temperature",0,1);
-        lcd.printString("Logging",0,2);
-        lcd.printString("Press A",0,3);
+        lcd.printString("     MODE     ",0,1);
+        lcd.printString("Washing Water",0,2);
+        lcd.printString("    Press A   ",0,3);
            
         lcd.refresh();
         wait(1);
-        //while (1){
-        if (g_A_flag){                               // Condition to change over into new loop
+         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();
+                WWtr();
                 wait(1);
-                }//}
-                
+                        }
 }
 void Page2()
 {        
@@ -213,7 +219,7 @@
         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.printString("    Press A   ",0,3);
            
         lcd.refresh();
         wait(1);
@@ -223,215 +229,276 @@
                 serial.printf("A Pressed");
                 CWtr();
                 wait(1);
-                        } 
+                        }                       
 }
-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)
-                                                                  
-        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,0,1);                // display on screen
-        serial.printf("T = %f C\n",T);                  // Printing the Temperature over Serial Port
-        
-        length = sprintf(buffer,"SP=%.2F 'C",Set);      // Print the Setpoint from the Float Variable Set 
-        if (length <= 14)                               // Ensuring string will fit on the screen (Printing at x=0)
-          lcd.printString(buffer,0,2);                  // display on screen
-        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();
     lcd.refresh();
     
-    int select = 0;
+    int Mode = 0;
     while (1){
         
     //serial.printf("Direction = %i ",d);
-    Direction d = Joystick.get_direction();
+    Direction d = Joystick.get_direction();                 // Joystick Direction used in order to switch between modes
 
-        switch(select) {
-            case 0:
-                switch(d) {
-                    case W:
-                        wait(0.5);
-                        select = 0;
-                        serial.printf("LEFT.0");
-                        break;
-                    case E:
-                        wait(0.5);
-                        select = 1;
-                        serial.printf("RIGHT.0");
-                        break;
+        switch(Mode) {                                      // Main External Switch to detetermine Mode              
+            case 0:                                         // Main Initial Case instance
+                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 = 0;                           // Remain in Mode 0 - Prevents idol cycling through the switch
+                        //serial.printf("LEFT.0");          // Debugging Print to see which state the Main switch is at via Direction           
+                        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 = 1;                           // Switch to Mode 1 
+                        //serial.printf("RIGHT.0");         // Debugging Print
+                        break;                              // Break out from Loop
                           }
-                break;
-            
-            case 1:
-                switch(d) {
-                    case W:
-                        wait(0.5);
-                        select = 0;
-                        serial.printf("LEFT.1");                
-                        break;
-                    case E:
-                        wait(0.5);
-                        select = 2;
-                        serial.printf("RIGHT.1");
-                        break;
-                          }
-                break;
+                break;                                      // Break out from Loop into Main Switch
             
-            case 2:
-                switch(d) {
-                    case W:
-                        wait(0.5);
-                        select = 1;
-                        serial.printf("LEFT.2");
-                        break;
-                    case E:
-                        wait(0.5);
-                        select = 2;
-                        serial.printf("RIGHT.2");
-                        break;
+            case 1:                                         // 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 = 0;                           // Return to Mode 0
+                        //serial.printf("LEFT.1");          // 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 = 2;                           // Switch to Mode 0                           
+                        //serial.printf("RIGHT.1");         // Debugging Print
+                        break;                              // Break out from Loop
                           }
-            break;
+                break;                                      // Break out from Loop into Main Switch
+            
+            case 2:                                         // 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 = 1;                           // 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 = 2;                           // 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.1);
+        wait(0.5);
 
-            if (select == 0){
-                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();                
-                        }
-            
-            if (select == 1){
-                Page1();                            
+            if (Mode == 0){
+                Home();
                             }
-            
-            if (select == 2){
+            else if (Mode == 1){
+                Page1();
+                            }
+            else if (Mode == 2){
                 Page2();
                             }
         }
 } 
-     
-void CWtr()
+void WWtr()
 {
+    /** 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 CWtr_SP = Setpoint[3];                        // Reading the Setpoint from the Array
-    //serial.printf("SP = %.2f \n",CWtr_SP);
-    //serial.printf("SETPOINT = ",CWtr_SP);
-        if (CWtr_SP-1 > T || T > CWtr_SP+1){            // If the Temperature is not within the Tolerance
+    float SP = Setpoint[1];                             // 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_Pg1();                           // Heating Cooling Control Function
+                lcd.clear();                            // Clear LCD Screen
+                T_SP_Pg1();                             // 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_Pg1();                           // Heating Cooling Control Function
+                lcd.clear();                            // Clear LCD Screen
+                T_SP_Pg1();                             // Print Modes Temperature & Setpoint info
+                lcd.printString("     Warm     ",0,2);  // Display string on screen, Determine Co-ordinates (..,Column, Row)
+                lcd.printString("Washing Water",0,3);
+                lcd.printString("    Ready!    ",4,4);    
+                
+                lcd.refresh();                          // Refresh & Display printed strings to LCD                          
+                Ready_LED = 0;                          // Enable the Ready 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 CWtr()
+{
+    /** Cold Drinking Water Mode
+      * Using Parameters for Safe Drinking Water Temperature
+      */
+    while(1){
+    
+    float T = tmp102.get_temperature();                 // Reading Temperature as a floating variable
+    float SP = Setpoint[0];                        // 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_Pg2();                           // Heating Cooling Control Function
                 lcd.clear();                            // Clear LCD Screen
                 T_SP_Pg2();                             // Print Modes Temperature & Setpoint info
-                lcd.printString("  Adjusting   ",0,2);              
+                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();
+                lcd.refresh();                          // Refresh & Display printed strings to LCD
                 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
+        else if (SP-1 <= T <= SP+1){          // If the Temperature is within the Tolerance
+                
+                HtgClg_Pg2();                           // Heating Cooling Control Function
+                lcd.clear();                            // Clear LCD Screen
+                T_SP_Pg2();                             // Print Modes Temperature & Setpoint info
+                lcd.printString("     COLD     ",0,2);  // Display string on screen, Determine Co-ordinates (..,Column, Row)
                 lcd.printString("Drinking Water",0,3);
                 lcd.printString("    Ready!    ",4,4);    
                 
-                Ready_LED = 0;
-        
-                lcd.refresh();
-                Ready_LED = 0;
+                lcd.refresh();                          // Refresh & Display printed strings to LCD                          
+                Ready_LED = 0;                          // Enable the Ready LED
                 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);
-                serial.printf("Home Pressed");
+        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;
+                    Clg_LED = 1;                        // Disable the LED's for next Mode
                     Htg_LED = 1;
                     Ready_LED = 1;
                 
-                MenuNav();
+                MenuNav();                              // Return to Navigation Menu
                 wait(1);
                 }
     }
 }
-
+void T_SP_Pg1()
+{
+        /** 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_1 = Setpoint[1];                 // 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_1);           // 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_1);         // Debugging Print
+}
+void HtgClg_Pg1()
+{
+        /** 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_1 = Setpoint[1];                 // Reading the Mode Setpoint from the Array
+            if (T > SP_1+2){                      // 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_1-2){                 // If Temp is below the setpoint
+                Htg_LED = 0;                    // Enable the Heating LED
+                Clg_LED = 1;                    // Disable other LED's
+                Ready_LED = 1;
+                serial.printf("Heating");
+                                   }
+            else {                              // If none of the conditions are satisfied
+                Clg_LED = 1;                    // Disable Heating & cooling LED's
+                Htg_LED = 1;                    
+                 }
+}
 void T_SP_Pg2()
 {
         /** 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
+          * 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 CWtr_SP = Setpoint[3];            // Reading the Mode Setpoint from the Array 
+    float SP_2 = Setpoint[0];                 // 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
-            //serial.printf("    T = %f C\n",T);
+            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",CWtr_SP);     // print the Setpoint from the Setpoint Variable
+            length = sprintf(buffer,"SP=%.2f 'C",SP_2);           // 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
-            //serial.printf("    T = %f C\n",CWtr_SP);
+            lcd.printString(buffer,13,1);                      // Display string on screen, Determine Co-ordinates (..,Column, Row)
+            //serial.printf("    T = %f C\n",SP_2);         // Debugging Print
 }
 void HtgClg_Pg2()
 {
         /** 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        
+            * 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 CWtr_SP = Setpoint[3];            // Reading the Mode Setpoint from the Array
-            if (T > CWtr_SP+1){                 // If Temp is above the setpoint
+        float SP_2 = Setpoint[0];                 // Reading the Mode Setpoint from the Array
+            if (T > SP_2+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 < CWtr_SP-1){            // If Temp is below the setpoint
-                Htg_LED = 1;                    // Enable the Heating LED
-                Clg_LED = 0;                    // Disable other LED's
+            else if (T < SP_2-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 {
+            else {                              // If none of the conditions are satisfied
                 Clg_LED = 1;                    // Disable Heating & cooling LED's
-                Htg_LED = 1;                    // As neither conditions are satisfied
+                Htg_LED = 1;                    
                  }
 }
\ No newline at end of file