Working Menu, additions to be made

Dependencies:   mbed

Revision:
13:f2dad2365841
Parent:
12:988bacb1c2a6
Child:
14:ef54ca605b6f
diff -r 988bacb1c2a6 -r f2dad2365841 main.cpp
--- a/main.cpp	Fri Feb 04 15:56:47 2022 +0000
+++ b/main.cpp	Fri Feb 04 17:50:48 2022 +0000
@@ -19,7 +19,7 @@
 DigitalOut red_led3(PTD3);
 
 DigitalIn button_A(PTB9); // Designating Buttons
-DigitalIn button_B(PTD0);
+//DigitalIn B(PTD0);
 DigitalIn button_X(PTC17);
 DigitalIn button_Y(PTC12);
 DigitalIn button_L(PTB18);
@@ -38,7 +38,7 @@
 InterruptIn sw2(SW2); // K64F on-board switches
 InterruptIn sw3(SW3);
 InterruptIn buttonStart(PTC5);
-InterruptIn buttonBack(PTB19);
+InterruptIn B(PTD0);
 
 DigitalOut r_led(LED_RED); // K64F on-board LEDs
 DigitalOut g_led(LED_GREEN);
@@ -48,15 +48,11 @@
 */
 void buttonStart_isr(); // Button Start interrupt service routine
 
-void buttonBack_isr(); // Button Back interrupt service routine
-
 void button_start_isr();
 
-void button_back_isr();
-
-volatile int S_flag, B_flag; // Global Variables
-volatile int g_buttonStart_flag = 0; 
-volatile int g_buttonBack_flag = 0; 
+void B_isr();
+ 
+void init_buttons(); // Initialise buttons
 
 void error(); // error function hangs flashing an LED
 
@@ -70,13 +66,22 @@
 
 void startup(); // Setting up startup
 
+void display_tmp(); // Tempertature display
+
+volatile int S_flag;  // Global Variables
+
+volatile int g_buttonStart_flag = 0; 
+
+volatile int g_buttonBack_flag = 0; 
+
+volatile int g_B_flag = 0;
 
 int main()
 {
 button_start.mode(PullDown);
 button_start.rise(button_start_isr);
-button_back.mode(PullDown);
-button_back.rise(button_back_isr);
+B.fall(&B_isr);
+B.mode(PullDown);
 
 init_K64F(); // Initialising the board, serial port, LED'S and joystick
 init_serial();
@@ -92,7 +97,6 @@
 startup(); // Initialising Startup
 
 while (1) {
-
 // these are settings that I have adjusted
 lcd.normalMode(); // normal colour mode
 lcd.setBrightness(0.75); // put LED backlight on 75%
@@ -115,6 +119,7 @@
 }
 }
 }
+
 void init_serial() {
 pc.baud(9600); // set to highest baud - ensure terminal software matches
 }
@@ -136,9 +141,9 @@
 red_led1.write(1); // LEDs are common anode (active-low) so writing a 1 will turn them off
 red_led2.write(1);
 red_led3.write(1);
-grn_led1.write(1);
+grn_led1.write(0);// LED on to show the board is on
 grn_led2.write(1);
-grn_led3.write(0); // LED on to show the board is on
+grn_led3.write(1); 
 }
 void lcd_sett()//LCD Set
 {
@@ -217,7 +222,7 @@
 /** Menu selection screen printed to LCD
 */
 if (select == 1){
-lcd.clear();
+lcd.clear(); // Clear display
 lcd.printString(" >Collection ", 0, 0); // Menu Selection, printing to LCD
 lcd.printString(" View Data ", 0, 1);
 lcd.printString(" Live Data ", 0, 2);
@@ -225,23 +230,26 @@
 lcd.refresh(); // Refresh display
 wait(0.3);}
 
-
 else if (select == 2) {
 lcd.printString(" Collection ", 0, 0);// Menu Selection, Printing to LCD
 lcd.printString(" >View Data ", 0, 1);
 lcd.printString(" Live Data ", 0, 2);
+lcd.printString(" About ", 0, 3);
 lcd.refresh(); // Refresh display
 wait(0.3);}
 
 else if (select == 3) {
+lcd.printString(" Collection ", 0, 0);// Menu Selection, Printing to LCD
 lcd.printString(" View Data ", 0, 1);// Menu Selection, Printing to LCD
 lcd.printString(" >Live Data ", 0, 2);
 lcd.printString(" About ", 0, 3);
 lcd.refresh(); // Refresh display
-wait(0.3);}
+wait(0.3);
+display_tmp();}
 
 else if (select == 4){
 lcd.printString(" Collection ", 0, 0);// Menu Selection, Printing to LCD
+lcd.printString(" View Data ", 0, 1);
 lcd.printString(" Live Data ", 0, 2);
 lcd.printString(" >About ", 0, 3);
 lcd.refresh(); // Refresh display
@@ -269,12 +277,31 @@
 lcd.refresh(); // Refresh display
 wait(3);
 }
+
 void button_start_isr()
 {
 S_flag = 1;
 }
 
-void button_back_isr()
+void B_isr()
+{
+g_B_flag = 1;
+}
+
+void display_tmp() // Displays Temperature on LCD
 {
-B_flag = 1;
+    
+char buffer[14]; //each character is 6 pixels wide, screen is 84 pixels (84/6 = 14) 
+if (g_B_flag)   { // Press button B to display Live data
+g_B_flag = 0; 
+B.rise(&B_isr);
+float T = tmp102.get_temperature(); // Get temperature and display                          
+int length = sprintf(buffer,"%.1f C",T);          
+if (length <= 14) {
+lcd.clear(); // Clear display
+lcd.printString("Temperature",0,1);
+lcd.printString(buffer,0,2);
+lcd.refresh();} // Refresh display  
+wait(3);
+}
 }
\ No newline at end of file