This program is an advanced "IoT" thermometer using LM75B component library. It displays the current value to the Serial host in Celcius or Fahrenheit (possible to change using a switch). It also stores an historic and displays it to the user using the LCD screen. Moreover, you can change the orientation of the screen by turning the device, just like a smartphone.

Dependencies:   C12832 FXOS8700CQ LM75B mbed

Revision:
1:06713d1b69cf
Parent:
0:362773c24009
Child:
2:5d0c209e5c61
--- a/main.cpp	Tue Feb 09 18:27:08 2016 +0000
+++ b/main.cpp	Tue Feb 09 21:41:48 2016 +0000
@@ -1,19 +1,20 @@
-#include "mbed.h"
-#include "LM75B.h"
-
-// #undef _DEBUG
-#define _DEBUG
+#include "main.h"
+#include "ThermalDisplayer.h"
 
-Serial host(USBTX, USBRX);
-LM75B lm_temp(D14, D15);
-InterruptIn sw2_int (SW2);
-Ticker rgb_tick;
-DigitalOut r_led (PTA2);
-DigitalOut g_led (PTC4);
-DigitalOut b_led (PTA0); // Won't use it because not working on my Shield !
+Serial host(USBTX, USBRX);      // Serial Host
+LM75B lm_temp(D14, D15);        // Thermal Sensor
+InterruptIn sw2_int(SW2);       // SW2
+DigitalOut r_led(PTA2);         // RGB LED
+DigitalOut g_led(PTC4);
+DigitalOut b_led(PTA0);         // Won't use BLUE because not working on my device !
+AnalogIn pot(A0);               // Potentiometer POT1
 
-volatile bool celcius = true;
+Ticker rgb_tick;                // Ticker for RGB LED control
+volatile bool celcius = true;   // Global boolean for unit Celcius / Fahrenheit
 
+/*
+ *  RGB LED control
+ */
 void rgb_handler() {
     if (celcius) {
         r_led = 1.0;
@@ -24,7 +25,10 @@
     }    
 }
 
-void sw_interrupt (void) {
+/*
+ *  SW2 handler
+ */
+void sw_handler (void) {
     celcius = !celcius;
 }
 
@@ -36,21 +40,41 @@
     g_led = 0.0;
     b_led = 1.0;    
     
-    rgb_tick.attach(&rgb_handler, 0.001);    
+    int refresh_time = 3000;
+    ThermalDisplayer *temp_display = new ThermalDisplayer();
+    
+    /*
+     * Thermal unit control
+     */
+    rgb_tick.attach(&rgb_handler, 0.001);
     sw2_int.mode(PullUp);
-    sw2_int.fall(&sw_interrupt);
+    sw2_int.fall(&sw_handler);  
+    
+    while (true) {     
         
-   /* forever.. */
-    while (true) {     
+        /*
+         * Get temperature using LM75B
+         * and display it to LCD screen
+         */
         float temperature = lm_temp.read();
+        temp_display->addTemp(temperature);
+        temp_display->display();
         
-        #if defined _DEBUG
+        
+        /* 
+         * Display value to host according to unit choosed with SW2. 
+         * Could have been ternary, but it's easier to read like this 
+         */
         if (celcius) {
             host.printf("Temp: %.2f deg Celcius.\r\n", temperature);
         } else {
             host.printf("Temp: %.2f deg Fahrenheit.\r\n", (temperature * 1.80 + 32.00));
         }
-        #endif
-        wait_ms(3000);
+        
+        /*
+         * Change refreh_time according to POT1's value 
+         */
+        refresh_time = (int) (MIN_REFRESH_TIME + (pot * (MAX_REFRESH_TIME - MIN_REFRESH_TIME)));
+        wait_ms(refresh_time);
     }
 }
\ No newline at end of file