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
Diff: main.cpp
- Revision:
- 4:5bf99eb2d740
- Parent:
- 3:a4dac093a968
- Child:
- 5:c5d7fca4d111
--- a/main.cpp Wed Feb 10 01:41:39 2016 +0000 +++ b/main.cpp Wed Feb 10 16:48:55 2016 +0000 @@ -1,12 +1,22 @@ +/** + * 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) + * + * Created by Guillaume Lefrant gtvl2 + **/ + #include "main.h" #include "ThermalDisplayer.h" Serial host(USBTX, USBRX); // Serial Host LM75B lm_temp(D14, D15); // Thermal Sensor InterruptIn sw2_int(SW2); // SW2 +DigitalOut tilt_led(LED1); // Red LED DigitalOut r_led(PTA2); // RGB LED DigitalOut g_led(PTC4); -DigitalOut b_led(PTA0); // Won't use BLUE because not working on my device ! +DigitalOut b_led(PTC12); AnalogIn pot(A0); // Potentiometer POT1 Ticker rgb_tick; // Ticker for RGB LED control @@ -19,10 +29,12 @@ { if (celcius) { r_led = 1.0; - g_led = 0.0; + g_led = 1.0; + b_led = 0.0; } else { r_led = 0.0; g_led = 1.0; + b_led = 1.0; } } @@ -39,7 +51,8 @@ host.baud(38400); host.printf("Hello gtvl2, from FRDM-K64F!\r\nUse POT1 to change the refresh rate, POT2 to change the scale of the graphic and SW2 to change the unit.\r\n"); - r_led = 0.0; + tilt_led = 0.0; + r_led = 1.0; g_led = 0.0; b_led = 1.0; @@ -54,14 +67,14 @@ sw2_int.fall(&sw_handler); while (true) { - + tilt_led = 0.0; /* * Get temperature using LM75B * and display it to LCD screen */ float temperature = lm_temp.read(); temp_display->addTemp(temperature); - temp_display->adjustScale(); + temp_display->adjustScale(host); temp_display->display(); /* @@ -71,12 +84,13 @@ 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)); + host.printf("Temp: %.2f deg Fahrenheit.\r\n", (temperature * 1.8f + 32.0f)); } /* * Change refresh_time according to POT1's value */ + tilt_led = 1.0; refresh_time = (int) (MIN_REFRESH_TIME + ((1.0f - pot) * (MAX_REFRESH_TIME - MIN_REFRESH_TIME))); wait_ms(refresh_time); }