(DA) Internet of Things and Smart Electronics- ELE3006M2122 / Mbed 2 deprecated Final_Project_V07_DLeaming_25574043

Dependencies:   mbed N5110v02 TMP102 JoystickIoT

Files at this revision

API Documentation at this revision

Comitter:
legstar85
Date:
Fri Dec 17 08:34:45 2021 +0000
Parent:
1:dd5fb735acf1
Child:
3:80c1eba78f9b
Commit message:
D.Leaming - 25574043 - University of Lincoln - IoT Project - V04

Changed in this revision

Joystick.lib Show annotated file Show diff for this revision Revisions of this file
N5110.lib Show annotated file Show diff for this revision Revisions of this file
TMP102.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Joystick.lib	Fri Dec 17 08:34:45 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/legstar85/code/JoystickIoT/#a68688213b63
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/N5110.lib	Fri Dec 17 08:34:45 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/legstar85/code/N5110v02/#200be703ee3b
--- a/TMP102.lib	Fri Feb 05 17:25:03 2016 +0000
+++ b/TMP102.lib	Fri Dec 17 08:34:45 2021 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/eencae/code/TMP102/#8818842a3573
+https://os.mbed.com/users/legstar85/code/TMP102/#d95a4e13f6cf
--- a/main.cpp	Fri Feb 05 17:25:03 2016 +0000
+++ b/main.cpp	Fri Dec 17 08:34:45 2021 +0000
@@ -1,74 +1,100 @@
-/* 
-
-2645_I2C_TMP102_Library
-
-Sample code from ELEC2645 Week 17 Lab
-
-Demonstrates how to re-factor the TMP102 code into a library
-
-(c) Craig A. Evans, University of Leeds, Feb 2016
-
+/* * Print String
+* @ File main.cpp
+* Prints a string of characters to the screen buffer, string is cut off after the 83rd  pixel.
+* @param x - the column number (0 to 83)
+* @param y - the row number (0-5) - the display is split into 6 banks - each bank can be considered a row
+* @author - David Leaming - 25574043
+* @ Date - December 2021
+*
+* Acknowledgements 
+* Craig A. Evans, University of Leeds, TMP102 Library ,Feb 2016
+* Dr Edmond Nurellari, University of Lincoln, Joystick & N5110 Libraries
+*
 */ 
 
-#include "mbed.h"
-// include the library header, ensure the library has been imported into the project
+#include "mbed.h"                                                               // include the library header, ensure the library has been imported into the project
 #include "TMP102.h"
+#include "N5110.h"
+#include "Joystick.h"
+#include "Bitmap.h"
 
-// Create TMP102 object
-TMP102 tmp102(I2C_SDA,I2C_SCL);  
-// UART connection for PC
-Serial pc(USBTX,USBRX);
+TMP102 tmp102(I2C_SDA,I2C_SCL);                                                 // Create TMP102 object  
+
+//        VCC,SCE,RST,D/C,MOSI,SCLK,LED 
+N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);                                      // Create Screen Object - K64F - pwr from 3V3, GND Pin also needs connecting
+
 
-// K64F on-board LEDs 
-DigitalOut r_led(LED_RED);
-DigitalOut g_led(LED_GREEN);
-DigitalOut b_led(LED_BLUE);
-// K64F on-board switches
-InterruptIn sw2(SW2);
-InterruptIn sw3(SW3);
+Serial pc(USBTX,USBRX);                                                         // UART connection for PC
+
+DigitalOut r_led(LED_RED);                                                      // K64F on-board LEDs 
+DigitalOut g_led(LED_GREEN);                                                    // K64F on-board LEDs 
+DigitalOut b_led(LED_BLUE);                                                     // K64F on-board LEDs 
 
-// error function hangs flashing an LED
-void error();
-// setup serial port
-void init_serial();
-// set-up the on-board LEDs and switches
-void init_K64F();
+InterruptIn sw2(SW2);                                                           // K64F on-board switches
+InterruptIn sw3(SW3);                                                           // K64F on-board switches
+
+void error();                                                                   // error function hangs flashing an LED
+void init_serial();                                                             // setup serial port
+void init_K64F();                                                               // set-up the on-board LEDs and switches
 
 int main()
 {
-    // initialise the board and serial port
-    init_K64F();
-    init_serial(); 
-    // call the sensor init method using dot syntax
-    tmp102.init();
+    init_K64F();                                                                // initialise the board
+    init_serial();                                                              // initialise the serial port
+    
+    tmp102.init();                                                              // call the sensor init method using dot syntax
+    lcd.init();                                                                 // initialise display
+    
+    lcd.setContrast(0.5);                                                       // change set contrast in range 0.0 to 1.0
     
     while (1) {
         
-        // read temperature and print over serial port
-        float T = tmp102.get_temperature();
-        pc.printf("T = %f K\n",T);
-        // small delay - 1s to match the update rate of the sensor (1 Hz)
-        wait(1.0);
+        lcd.normalMode();                                                       // normal colour mode
+        lcd.setBrightness(0.5);                                                 // put LED backlight on 50%
+        lcd.clear();                                                            // clear buffer at start of every loop
+        
+        char buffer[14];                                                        // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
+
+        
+        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);
+
+        lcd.refresh();                                                          // need to refresh display after setting pixels or writing strings
+        wait(2.0);     
+        
+        lcd.clear();                                                            // clear buffer at start of every loop
+        lcd.refresh();                                                          // need to refresh display after setting pixels or writing strings 
+        wait(0.5);
+        
+        float T = tmp102.get_temperature();                                     // read temperature and print to lcd
+        length = sprintf(buffer,"T = %.2f C",T);
+        if (length <= 14)
+        lcd.printString(buffer,0,2);
+        lcd.refresh();                                                          // need to refresh display after setting pixels or writing strings 
+        wait(2.0);
         
     }
 
 }
 
 void init_serial() {
-    // set to highest baud - ensure terminal software matches
-    pc.baud(115200); 
+    pc.baud(115200);                                                            // set to highest baud - ensure terminal software matches
 }
 
 void init_K64F() 
 {
-    // on-board LEDs are active-low, so set pin high to turn them off.
-    r_led = 1;
-    g_led = 1;
-    b_led = 1;   
+    r_led = 1;                                                                  // on-board LEDs are active-low, so set pin high to turn them off.
+    g_led = 1;                                                                  // on-board LEDs are active-low, so set pin high to turn them off.
+    b_led = 1;                                                                  // on-board LEDs are active-low, so set pin high to turn them off.
     
-    // since the on-board switches have external pull-ups, we should disable the internal pull-down
-    // resistors that are enabled by default using InterruptIn
-    sw2.mode(PullNone);
-    sw3.mode(PullNone);
+    sw2.mode(PullNone);                                                         // since the on-board switches have external pull-ups, we should disable the internal pull-down
+    sw3.mode(PullNone);                                                         // resistors that are enabled by default using InterruptIn
 
 }
--- a/mbed.bld	Fri Feb 05 17:25:03 2016 +0000
+++ b/mbed.bld	Fri Dec 17 08:34:45 2021 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/f141b2784e32
\ No newline at end of file
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file