Rev 1.6 - Sample Period Work in progress

Dependencies:   mbed Bitmap N5110 TMP102 Joystick

Revision:
9:77a6ea988e01
Parent:
8:9c5ef970de26
Child:
10:d98b2dd7ba09
--- a/main.cpp	Fri Jan 07 09:21:20 2022 +0000
+++ b/main.cpp	Sat Jan 08 18:29:45 2022 +0000
@@ -26,7 +26,7 @@
 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
-Timer timer();                                 // USE FOR LOGGING BETWEEN 0-10s
+//Timer timer();                                 // USE FOR LOGGING BETWEEN 0-10s
 
 DigitalOut RED_led(LED_RED);                   // On-board K64F LED'S
 DigitalOut GRN_led(LED_GREEN);
@@ -34,12 +34,18 @@
 
 InterruptIn sw2(SW2);                          // On-board K64F Switches
 InterruptIn sw3(SW3);
+InterruptIn R(PTB3);                         // Right Bumper Button
+InterruptIn L(PTB18);                        // Left Bumper Button
 
+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
 
 /*======================= Void Declaration ===================================*/
 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 L_isr();
 
 /*======================== Main Function =====================================*/
 int main()
@@ -50,49 +56,72 @@
     tmp102.init();                              // Initialise Temp Sensor
     lcd.init();                                 // Initialise LCD
         
-    lcd.setContrast(0.4);
+    lcd.setContrast(0.4);                       // Setup the contrast for the LCD Screen
+    R.fall(&R_isr);
+    R.mode(PullDown);
+    
+    L.fall(&L_isr);
+    L.mode(PullDown);
     
     while (1) {
         
         //timer.start(); 
         //for(i = 0; i < 10; i++){
         // read temperature and print over serial port
-        float T = tmp102.get_temperature();
-        serial.printf("T = %f C\n",T);
+        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        
+        if (g_L_flag){                                  // Condition to change over into new loop
+        g_L_flag = 0;       
+        L.fall(&L_isr);
+        serial.printf("T = %f C\n",T);                  // Printing the Temperature over Serial Port
         //serial.printf("%2.2fs: %3.1f deg C\n\r", timer.read(), T);
-        //timer.end();
         
-        // small delay - 1s to match the update rate of the sensor (1 Hz)
-         lcd.clear(); // clear buffer at start of every loop
-        // can directly print strings at specified co-ordinates (must be less than 84 pixels to fit on display)
-        lcd.printString("Temperature",0,0);
-
-        char buffer[14];  // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters)
-        // or create formatted strings - ensure they aren't more than 14 characters long
+        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)
+                                                        // Therefor strings csn not exceed the 14 Character Limit
         
-        int length = sprintf(buffer,"T=%.2F 'C",T); // print formatted data to buffer
-        // it is important the format specifier ensures the length will fit in the buffer
-        if (length <= 14)  // if string will fit on display (assuming printing at x=0)
-            lcd.printString(buffer,0,1);           // display on screen
+        int length = sprintf(buffer,"T=%.2F 'C",T);     // print the temperature from the float variable T
+                                                        // it is important the format specifier ensures the length will fit in the buffer
+        if (length <= 14)                               // Ensuring string will fit on the screen (Printing at x=0)
+            lcd.printString(buffer,0,1);                // display on screen
         
-        float Set = 100 * SP; 
-        length = sprintf(buffer,"SP=%.2F 'C",Set);
-        if (length <= 14)  // if string will fit on display (assuming printing at x=0)
-          lcd.printString(buffer,0,2);           // display on screen
-        serial.printf("   SP = %f",  Set);   
-        
+                                                        // Multiplying the Floating variable by 100 in order to gain a larger range 
+        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);              // 
+               
+        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.0);
+                                             
         
-        if (Set < T){
-        lcd.clear();
-        lcd.printString("Over Heating",3,2);
-        //serial.printf("OverTemp");
+        if (g_R_flag){                                 // Condition to change over into new loop
+        g_R_flag = 0;
+        R.rise(&R_isr);       
+        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.8",0,4);
+        
         }
-        lcd.refresh();
-        wait(1.0);
+        lcd.refresh();                                  
+        wait(1.0); 
         
+             
     }
+}
+}
 
-}
 /*
 =========================== Void Setup =========================================
 Custom Function's are called Void's, which are called upon inside the of the
@@ -100,7 +129,7 @@
 */
 
 void init_serial() {
-        // Baud Rate Communication for CoolTerm Debugging
+                                        // Baud Rate Communication for CoolTerm Debugging
     serial.baud(9600);                          
 }
 
@@ -109,16 +138,26 @@
         // on-board LEDs are active when 0, so setting the pin to 1 turns them off.
     RED_led = 1;
     GRN_led = 1;
-    BLU_led = 1;   
-    
-        /* since the on-board switches have external pull-ups, disable the 
-         * internal pull-down resistors that are enabled by default using
-         * the InterruptIn Command */
+    BLU_led = 1;       
+                       /* since the on-board switches have external pull-ups, disable the 
+                        * internal pull-down resistors that are enabled by default using
+                        * the InterruptIn Command */
     sw2.mode(PullNone);
     sw3.mode(PullNone);
+}
 
+void R_isr()                            // Right Bumper Interrupt Service     
+{
+    g_R_flag = 1;                       // set flag in ISR
 }
-/* void init_BP()
+
+void L_isr()                            // Left Bumper Interrupt Service     
+{
+    g_L_flag = 1;                       // set flag in ISR
+}
+/*
+ void init_PCB()
 {
     
-}
\ No newline at end of file
+}
+*/
\ No newline at end of file