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

main.cpp

Committer:
co838_gtvl2
Date:
2016-02-09
Revision:
0:362773c24009
Child:
1:06713d1b69cf

File content as of revision 0:362773c24009:

#include "mbed.h"
#include "LM75B.h"

// #undef _DEBUG
#define _DEBUG

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 !

volatile bool celcius = true;

void rgb_handler() {
    if (celcius) {
        r_led = 1.0;
        g_led = 0.0;
    } else {
        r_led = 0.0;
        g_led = 1.0;
    }    
}

void sw_interrupt (void) {
    celcius = !celcius;
}

int main(void) {
    host.baud(38400);
    host.printf("Hello LeNiglo, from FRDM-K64F!\r\n");
        
    r_led = 0.0;
    g_led = 0.0;
    b_led = 1.0;    
    
    rgb_tick.attach(&rgb_handler, 0.001);    
    sw2_int.mode(PullUp);
    sw2_int.fall(&sw_interrupt);
        
   /* forever.. */
    while (true) {     
        float temperature = lm_temp.read();
        
        #if defined _DEBUG
        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);
    }
}