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

Committer:
co838_gtvl2
Date:
Wed Feb 10 16:48:55 2016 +0000
Revision:
4:5bf99eb2d740
Parent:
3:a4dac093a968
Child:
6:6c61186c8739
WOW !; Speed of display x100 and ability to reverse screen using accelerometer !

Who changed what in which revision?

UserRevisionLine numberNew contents of line
co838_gtvl2 1:06713d1b69cf 1 #include "ThermalDisplayer.h"
co838_gtvl2 1:06713d1b69cf 2
co838_gtvl2 2:5d0c209e5c61 3 /*
co838_gtvl2 2:5d0c209e5c61 4 * Constructor, initialize Potentiometer, LCD and variables
co838_gtvl2 2:5d0c209e5c61 5 */
co838_gtvl2 4:5bf99eb2d740 6 ThermalDisplayer::ThermalDisplayer(): pot(A1), accel(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1)
co838_gtvl2 2:5d0c209e5c61 7 {
co838_gtvl2 2:5d0c209e5c61 8 this->lcd = new C12832(D11, D13, D12, D7, D10);
co838_gtvl2 4:5bf99eb2d740 9 this->lcd->set_auto_up(0);
co838_gtvl2 2:5d0c209e5c61 10 this->temperatures = std::list<float>(MAX_SIZE);
co838_gtvl2 2:5d0c209e5c61 11 this->minScale = MIN_MIN_SCALE;
co838_gtvl2 2:5d0c209e5c61 12 this->maxScale = MAX_MAX_SCALE;
co838_gtvl2 4:5bf99eb2d740 13 this->screenOrientation = true;
co838_gtvl2 4:5bf99eb2d740 14 this->accel.enable();
co838_gtvl2 1:06713d1b69cf 15 }
co838_gtvl2 1:06713d1b69cf 16
co838_gtvl2 2:5d0c209e5c61 17 /*
co838_gtvl2 2:5d0c209e5c61 18 * Add record to temperature historic
co838_gtvl2 2:5d0c209e5c61 19 */
co838_gtvl2 2:5d0c209e5c61 20 void ThermalDisplayer::addTemp(const float &temp)
co838_gtvl2 2:5d0c209e5c61 21 {
co838_gtvl2 1:06713d1b69cf 22 this->temperatures.pop_front();
co838_gtvl2 1:06713d1b69cf 23 this->temperatures.push_back(temp);
co838_gtvl2 1:06713d1b69cf 24 }
co838_gtvl2 1:06713d1b69cf 25
co838_gtvl2 2:5d0c209e5c61 26 /*
co838_gtvl2 2:5d0c209e5c61 27 * Display informations to the LCD screen
co838_gtvl2 3:a4dac093a968 28 * Screen isn't even flusing !
co838_gtvl2 2:5d0c209e5c61 29 */
co838_gtvl2 2:5d0c209e5c61 30 void ThermalDisplayer::display()
co838_gtvl2 2:5d0c209e5c61 31 {
co838_gtvl2 1:06713d1b69cf 32 list<float>::const_iterator it;
co838_gtvl2 2:5d0c209e5c61 33
co838_gtvl2 1:06713d1b69cf 34 int pos = 0;
co838_gtvl2 1:06713d1b69cf 35 for (it = this->temperatures.begin(); it != this->temperatures.end(); it++, pos++) {
co838_gtvl2 2:5d0c209e5c61 36 int height = (int) (32 * ((*it) - this->minScale) / (this->maxScale - this->minScale));
co838_gtvl2 4:5bf99eb2d740 37 height = height > DISPLAY_Y ? DISPLAY_Y : (height < 0 ? 0 : height);
co838_gtvl2 3:a4dac093a968 38 /*
co838_gtvl2 3:a4dac093a968 39 * Draw a white rectangle to erase previous data.
co838_gtvl2 4:5bf99eb2d740 40 * Then, draw on top of it the new data.
co838_gtvl2 3:a4dac093a968 41 */
co838_gtvl2 4:5bf99eb2d740 42 if (this->screenOrientation) {
co838_gtvl2 4:5bf99eb2d740 43 this->lcd->rect(pos * 2, 0, pos * 2 + 1, DISPLAY_Y, 0);
co838_gtvl2 4:5bf99eb2d740 44 this->lcd->rect(pos * 2, DISPLAY_Y - height, pos * 2 + 1, DISPLAY_Y, 1);
co838_gtvl2 4:5bf99eb2d740 45 } else {
co838_gtvl2 4:5bf99eb2d740 46 this->lcd->rect(DISPLAY_X - (pos * 2), 0, DISPLAY_X - (pos * 2 + 1), DISPLAY_Y, 0);
co838_gtvl2 4:5bf99eb2d740 47 this->lcd->rect(DISPLAY_X - (pos * 2), 0, DISPLAY_X - (pos * 2 + 1), height, 1);
co838_gtvl2 4:5bf99eb2d740 48 }
co838_gtvl2 1:06713d1b69cf 49 }
co838_gtvl2 4:5bf99eb2d740 50 this->lcd->copy_to_lcd();
co838_gtvl2 2:5d0c209e5c61 51 }
co838_gtvl2 2:5d0c209e5c61 52
co838_gtvl2 2:5d0c209e5c61 53 /*
co838_gtvl2 2:5d0c209e5c61 54 * Adjust scale of the display according to POT2
co838_gtvl2 4:5bf99eb2d740 55 * Also adjust the screen orientation accodring to FXOS8700CQ accelerometer
co838_gtvl2 2:5d0c209e5c61 56 */
co838_gtvl2 4:5bf99eb2d740 57 void ThermalDisplayer::adjustScale(Serial &host)
co838_gtvl2 2:5d0c209e5c61 58 {
co838_gtvl2 2:5d0c209e5c61 59 float potValue = this->pot;
co838_gtvl2 2:5d0c209e5c61 60
co838_gtvl2 2:5d0c209e5c61 61 this->minScale = MIN_MIN_SCALE + potValue * (MAX_MIN_SCALE - MIN_MIN_SCALE);
co838_gtvl2 2:5d0c209e5c61 62 this->maxScale = MIN_MAX_SCALE + (1.0f - potValue) * (MAX_MAX_SCALE - MIN_MAX_SCALE);
co838_gtvl2 4:5bf99eb2d740 63
co838_gtvl2 4:5bf99eb2d740 64 SRAWDATA accel_data;
co838_gtvl2 4:5bf99eb2d740 65 SRAWDATA magn_data;
co838_gtvl2 4:5bf99eb2d740 66 uint8_t data = this->accel.get_data(&accel_data, &magn_data);
co838_gtvl2 4:5bf99eb2d740 67 if (accel_data.y <= -100) {
co838_gtvl2 4:5bf99eb2d740 68 this->screenOrientation = false;
co838_gtvl2 4:5bf99eb2d740 69 } else {
co838_gtvl2 4:5bf99eb2d740 70 this->screenOrientation = true;
co838_gtvl2 4:5bf99eb2d740 71 }
co838_gtvl2 1:06713d1b69cf 72 }