Rev 1.6 - Sample Period Work in progress

Dependencies:   mbed Bitmap N5110 TMP102 Joystick

Revision:
7:ef1dab708752
Parent:
6:117edd5dc0a0
Child:
8:9c5ef970de26
--- a/main.cpp	Thu Dec 16 15:48:12 2021 +0000
+++ b/main.cpp	Thu Dec 30 15:49:14 2021 +0000
@@ -1,59 +1,59 @@
 /* 
 
-2645_I2C_TMP102_Library
-
-Sample code from ELEC2645 Week 17 Lab
+Acknowledgements to (c) Craig A. Evans, University of Leeds, Feb 2016 for Temp Library
+Acknowledgements to (c) Dr. Edmond Nurellari, University of Lincoln, Dec 2021 for Classes used
 
-Demonstrates how to re-factor the TMP102 code into a library
-
-(c) Craig A. Evans, University of Leeds, Feb 2016
-
+Using Various Libraries & Functions in order to create a 
+Temperature Based Health Assistive Smart Device
 */ 
 
-#include "mbed.h"
-// include the library header, ensure the library has been imported into the project
-#include "TMP102.h"
-#include "N5110.h"
-#include "Bitmap.h"
+/*
+======================== Library Imports =======================================
+Importing the Header Files from the Class Libraries into the main.cpp
+*/
+#include "mbed.h"                               // Mbed OS Library
+#include "TMP102.h"                             // TMP102 Header File
+#include "N5110.h"                              // N5110 Header File 
+#include "Bitmap.h"                             // Bitmap Header File 
+
 
-// Create TMP102 object
-TMP102 tmp102(I2C_SDA,I2C_SCL);  
-N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
-// UART connection for PC
-Serial serial(USBTX,USBRX);
-AnalogIn SP(PTB2);
+/*
+========================== Vairable Setup ======================================
+Pre-Determining the various Variable names to hardware pins on the K64F Board
+*/
 
-// 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);
+TMP102 tmp102(I2C_SDA,I2C_SCL);                // Create TMP102 object
+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
+
+DigitalOut RED_led(LED_RED);                   // On-board K64F LED'S
+DigitalOut GRN_led(LED_GREEN);
+DigitalOut BLU_led(LED_BLUE);
+
+InterruptIn sw2(SW2);                          // On-board K64F Switches
 InterruptIn sw3(SW3);
 
-// 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();
+//Timer timer(); // USE FOR LOGGING BETWEEN 0-10s
+/*======================= Void Declaration ===================================*/
+void error();                                  // Error Hang Code Function
+void init_serial();                            // Setup serial port Function
+void init_K64F();                              // K64F Disabling Onboard Components Function
 
-
+/*======================== Main Function =====================================*/
 int main()
 {
-    // initialise the board and serial port
-    init_K64F();
-    init_serial(); 
-    // call the sensor init method using dot syntax
-    tmp102.init();
-    lcd.init();
     
-    
-    
+    init_K64F();                                // Initialise K64F Board
+    init_serial();                              // Initialise Serial Port
+    tmp102.init();                              // Initialise Temp Sensor
+    lcd.init();                                 // Initialise LCD
+        
     lcd.setContrast(0.4);
     
     while (1) {
         
+        //timer.start();
         // read temperature and print over serial port
         float T = tmp102.get_temperature();
         serial.printf("T = %f C\n",T);
@@ -61,53 +61,60 @@
         // small delay - 1s to match the update rate of the sensor (1 Hz)
          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("Lets Gan!",0,0);
+        lcd.printString("Temperature",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
+        char buffer[14];  // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14 Max amound of Characters)
         // or create formatted strings - ensure they aren't more than 14 characters long
-        // int temperature = 27;
         
         int length = sprintf(buffer,"T=%.2F 'C",T); // 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,2);           // display on screen
+            lcd.printString(buffer,0,1);           // display on screen
         
-        float Set = 33 * SP; 
+        float Set = 100 * SP; 
         length = sprintf(buffer,"SP=%.2F 'C",Set);
         if (length <= 14)  // if string will fit on display (assuming printing at x=0)
-          lcd.printString(buffer,0,4);           // display on screen
+          lcd.printString(buffer,0,2);           // display on screen
         serial.printf("   SP = %f",  Set);   
-        /*
-        float pressure = 1012.3;  // same idea with floats
-        length = sprintf(buffer,"P = %.2f mb",pressure);
-        if (length <= 14)
-            lcd.printString(buffer,0,3);
-        */
+        
         
+        if (Set < T){
+        lcd.clear();
+        lcd.printString("Over Heating",3,2);
+        //serial.printf("OverTemp");
+        }
         lcd.refresh();
-
         wait(1.0);
         
     }
 
 }
+/*
+=========================== Void Setup =========================================
+Custom Function's are called Void's, which are called upon inside the of the
+Main Function Code
+*/
 
 void init_serial() {
-    // set to highest baud - ensure terminal software matches
-    serial.baud(9600); 
+        // Baud Rate Communication for CoolTerm Debugging
+    serial.baud(9600);                          
 }
 
 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;   
+        // on-board LEDs are active when 0, so setting the pin to 1 turns them off.
+    RED_led = 1;
+    GRN_led = 1;
+    BLU_led = 1;   
     
-    // since the on-board switches have external pull-ups, we should disable the internal pull-down
-    // resistors that are enabled by default using InterruptIn
+        /* since the on-board switches have external pull-ups, disable the 
+         * internal pull-down resistors that are enabled by default using
+         * the InterruptIn Command */
     sw2.mode(PullNone);
     sw3.mode(PullNone);
 
 }
+/* void init_BP()
+{
+    
+}
\ No newline at end of file