Rev 1.6 - Sample Period Work in progress

Dependencies:   mbed Bitmap N5110 TMP102 Joystick

Revision:
12:1c821d6d50f9
Parent:
11:d8bd197a5e7b
Child:
13:70f02d5e56f5
--- a/main.cpp	Sat Jan 08 18:44:55 2022 +0000
+++ b/main.cpp	Sat Jan 15 19:39:12 2022 +0000
@@ -15,7 +15,7 @@
 #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 ======================================
@@ -26,6 +26,8 @@
 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
+Joystick Joystick(PTB10,PTB11,PTC16);          // Create Joystick (PTB10 = Up/Down) (PTB11 = L/R) (PTB16 = Button)
+
 //Timer timer();                                 // USE FOR LOGGING BETWEEN 0-10s
 
 DigitalOut RED_led(LED_RED);                   // On-board K64F LED'S
@@ -47,6 +49,7 @@
 void R_isr();
 void L_isr();
 void info();
+void temp_SP();
 
 /*======================== Main Function =====================================*/
 int main()
@@ -56,6 +59,7 @@
     init_serial();                              // Initialise Serial Port
     tmp102.init();                              // Initialise Temp Sensor
     lcd.init();                                 // Initialise LCD
+    Joystick.init();
         
     lcd.setContrast(0.4);                       // Setup the contrast for the LCD Screen
     R.fall(&R_isr);
@@ -64,56 +68,26 @@
     L.fall(&L_isr);
     L.mode(PullDown);
     
-    while (1) {
-        
+    while (1) {        
         //timer.start(); 
         //for(i = 0; i < 10; i++){
         // read temperature and print over serial port
-        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        
-
-        while (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);       
-        info();                                         // Call the info function           
+                                                                       
+        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);       
+            info();                                         // Call the info function           
         }
         lcd.refresh();                                  
         wait(1.0); 
 
         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);
-        
-        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 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
-        
-                                                        // 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
-        }
+            g_L_flag = 0;       
+            L.fall(&L_isr);
+            temp_SP();
         lcd.refresh();                                  
         wait(1.0);
-                                                     
-
-        
-             
+                                                                
     }
 }
 }
@@ -159,12 +133,131 @@
         lcd.printString("Author:",0,1);
         lcd.printString("Louis M",0,2);
         lcd.printString("18689006",0,3);
-        lcd.printString("Version 1.8.1",0,4);   
+        lcd.printString("Version 1.9",0,4);   
     
-}   
-/*
- void init_Menu()
+} 
+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("Page Down",0,5);   
     
 }
-*/
\ No newline at end of file
+void Page2()
+{
+        serial.printf(" Page 2 ");  // Debugging Print
+        lcd.clear();                                   // Clear Screen
+        lcd.printString("    Page 2    ",0,1);              // Print Information Screen
+        lcd.printString("Blood Pressure",0,2);
+        lcd.printString("Logging",0,3);
+        lcd.printString("Press A",0,5);
+        lcd.printString("Page Up",0,0);   
+    
+}  
+void temp_SP()
+{
+        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        
+        
+        //serial.printf("%2.2fs: %3.1f deg C\n\r", timer.read(), T);
+        
+        //if (T > Set){
+        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 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);              // 
+        
+        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   
+        }
+}    
+void init_Menu()
+{
+    Joystick.init();
+    Direction d = Joystick.get_direction();
+    serial.printf("Direction = %i/n ",d);
+
+    int select = 0;
+    while (1) {
+        switch(select) {
+            case 0:
+                switch(d) {
+                    case N:
+                        select = 1;
+                        serial.printf("UP");
+                        break;
+                    case S:
+                        select = 2;
+                        serial.printf("DOWN");
+                        break;
+                }
+                break;
+            case 1:
+                switch(d) {
+                    case N:
+                        select = 2;
+                        serial.printf("UP");
+                        break;
+                    case S:
+                        select = 0;
+                        serial.printf("DOWN");
+                        break;
+            case 2:
+                switch(d) {
+                    case N:
+                        select = 0;
+                        serial.printf("UP");
+                        break;
+                    case S:
+                        select = 1;
+                        serial.printf("DOWN");
+                        break;
+        }
+        wait(1);
+
+            if (select == 0){
+                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);    
+                }
+                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("R Pressed");
+                }
+            else if (select == 1){
+                serial.printf("Page1");
+                Page1();
+                }
+                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("R Pressed");
+                }
+            else if (select == 2){
+                serial.printf("Page2");
+                Page2();
+                }
+        
+}
+}
+}
+}
\ No newline at end of file