(DA) Internet of Things and Smart Electronics- ELE3006M2122 / Mbed OS AnimalTempChecker
Revision:
3:0a85cca4faa3
Parent:
2:33af3e378563
Child:
4:14ea6bb0dbad
--- a/main.cpp	Thu Dec 16 11:15:18 2021 +0000
+++ b/main.cpp	Thu Dec 16 11:33:20 2021 +0000
@@ -11,11 +11,15 @@
 */ 
 
 #include "mbed.h"
-// include the library header, ensure the library has been imported into the project
 #include "TMP102.h"
+#include "Bitmap.h"
+#include "N5110.h"
+// include the library header folders, ensure the library has been imported into the project file
+
 
 // Create TMP102 object
-TMP102 tmp102(I2C_SDA,I2C_SCL);  
+TMP102 tmp102(I2C_SDA,I2C_SCL); 
+N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
 // UART connection for PC
 Serial pc(USBTX,USBRX);
 
@@ -41,6 +45,9 @@
     init_serial(); 
     // call the sensor init method using dot syntax
     tmp102.init();
+    lcd.init();
+
+    lcd.setContrast(0.4);
     
     while (1) {
         
@@ -49,6 +56,35 @@
         pc.printf("T = %f K\n",T);
         // small delay - 1s to match the update rate of the sensor (1 Hz)
         wait(1.0);
+                
+        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("Hello, World!",0,0);
+
+        char buffer[14];  // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
+        // so can display a string of a maximum 14 characters in length
+        // or create formatted strings - ensure they aren't more than 14 characters long
+        int temperature = 27;
+        int length = sprintf(buffer,"T = %2d C",temperature); // 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
+
+        float pressure = 1012.3;  // same idea with floats
+        length = sprintf(buffer,"P = %.2f mb",pressure);
+        if (length <= 14)
+            lcd.printString(buffer,0,2);
+
+        // can also print individual characters at specified place
+        lcd.printChar('X',5,3);
+
+        // draw a line across the display at y = 40 pixels (origin top-left)
+        for (int i = 0; i < WIDTH; i++) {
+            lcd.setPixel(i,40,true);
+        }
+        // need to refresh display after setting pixels or writing strings
+        lcd.refresh();
+        wait(5.0);
         
     }