Becky Page / Mbed OS Assignment1081
Revision:
1:aef8ec8d23d8
Parent:
0:44f87c90421e
Child:
2:daceae26f5df
diff -r 44f87c90421e -r aef8ec8d23d8 main.cpp
--- a/main.cpp	Fri Nov 20 15:13:10 2020 +0000
+++ b/main.cpp	Fri Nov 27 09:25:06 2020 +0000
@@ -25,6 +25,10 @@
 #define BLINKING_RATE_MS 500
 #define SW2 P0_4
 
+char buffer[80];
+/* prototype of function */
+void displayAt( int x, int y, char *buffer );
+
 int main()
 {
     // Initialise the digital pin LED1 as an output
@@ -33,7 +37,9 @@
     AnalogIn vTherm(P10_1);
     DigitalOut thermVcc(P10_3);
     DigitalOut thermGnd(P10_0);
-    
+    printf("\033[2J\033[H"); // clear screen and move the cursor to 0, 0
+    printf("\033[?25l"); // Turn off visible cursor
+    fflush(stdout); // send the codes to the terminal
     thermVcc = 1;
     thermGnd = 0;
     while (true) {
@@ -52,8 +58,14 @@
  
     float temperatureC = (float32_t)(((1.0 / stEqn) - 273.15)  + 0.5);
 
-            printf("Temperature is %f\r\n", temperatureC);
+            sprintf(buffer, "Temperature is %f\r\n", temperatureC);
+            displayAt(0, 3, buffer);
         }
         thread_sleep_for(BLINKING_RATE_MS);
     }
 }
+
+void displayAt( int x, int y, char *buffer ) {
+    printf( "\033[%d;%dH%s", y, x, buffer);
+    fflush(stdout);
+    }
\ No newline at end of file