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 01:41:39 2016 +0000
Revision:
3:a4dac093a968
Parent:
2:5d0c209e5c61
Child:
4:5bf99eb2d740
Working Version 1.0

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 2:5d0c209e5c61 6 ThermalDisplayer::ThermalDisplayer(): pot(A1)
co838_gtvl2 2:5d0c209e5c61 7 {
co838_gtvl2 2:5d0c209e5c61 8 this->lcd = new C12832(D11, D13, D12, D7, D10);
co838_gtvl2 2:5d0c209e5c61 9 this->temperatures = std::list<float>(MAX_SIZE);
co838_gtvl2 2:5d0c209e5c61 10 this->minScale = MIN_MIN_SCALE;
co838_gtvl2 2:5d0c209e5c61 11 this->maxScale = MAX_MAX_SCALE;
co838_gtvl2 1:06713d1b69cf 12 }
co838_gtvl2 1:06713d1b69cf 13
co838_gtvl2 2:5d0c209e5c61 14 /*
co838_gtvl2 2:5d0c209e5c61 15 * Add record to temperature historic
co838_gtvl2 2:5d0c209e5c61 16 */
co838_gtvl2 2:5d0c209e5c61 17 void ThermalDisplayer::addTemp(const float &temp)
co838_gtvl2 2:5d0c209e5c61 18 {
co838_gtvl2 1:06713d1b69cf 19 this->temperatures.pop_front();
co838_gtvl2 1:06713d1b69cf 20 this->temperatures.push_back(temp);
co838_gtvl2 1:06713d1b69cf 21 }
co838_gtvl2 1:06713d1b69cf 22
co838_gtvl2 2:5d0c209e5c61 23 /*
co838_gtvl2 2:5d0c209e5c61 24 * Display informations to the LCD screen
co838_gtvl2 3:a4dac093a968 25 * Screen isn't even flusing !
co838_gtvl2 2:5d0c209e5c61 26 */
co838_gtvl2 2:5d0c209e5c61 27 void ThermalDisplayer::display()
co838_gtvl2 2:5d0c209e5c61 28 {
co838_gtvl2 1:06713d1b69cf 29 list<float>::const_iterator it;
co838_gtvl2 2:5d0c209e5c61 30
co838_gtvl2 1:06713d1b69cf 31 int pos = 0;
co838_gtvl2 1:06713d1b69cf 32 for (it = this->temperatures.begin(); it != this->temperatures.end(); it++, pos++) {
co838_gtvl2 2:5d0c209e5c61 33 int height = (int) (32 * ((*it) - this->minScale) / (this->maxScale - this->minScale));
co838_gtvl2 3:a4dac093a968 34 /*
co838_gtvl2 3:a4dac093a968 35 * Draw a white rectangle to erase previous data.
co838_gtvl2 3:a4dac093a968 36 * Then, draw again.
co838_gtvl2 3:a4dac093a968 37 */
co838_gtvl2 3:a4dac093a968 38 this->lcd->rect(pos * 2, 0, pos * 2 + 1, 32, 0);
co838_gtvl2 2:5d0c209e5c61 39 this->lcd->rect(pos * 2, height < 0 ? 31 : 32 - height, pos * 2 + 1, 32, 1);
co838_gtvl2 1:06713d1b69cf 40 }
co838_gtvl2 2:5d0c209e5c61 41 }
co838_gtvl2 2:5d0c209e5c61 42
co838_gtvl2 2:5d0c209e5c61 43 /*
co838_gtvl2 2:5d0c209e5c61 44 * Adjust scale of the display according to POT2
co838_gtvl2 2:5d0c209e5c61 45 */
co838_gtvl2 2:5d0c209e5c61 46 void ThermalDisplayer::adjustScale()
co838_gtvl2 2:5d0c209e5c61 47 {
co838_gtvl2 2:5d0c209e5c61 48 float potValue = this->pot;
co838_gtvl2 2:5d0c209e5c61 49
co838_gtvl2 2:5d0c209e5c61 50 this->minScale = MIN_MIN_SCALE + potValue * (MAX_MIN_SCALE - MIN_MIN_SCALE);
co838_gtvl2 2:5d0c209e5c61 51 this->maxScale = MIN_MAX_SCALE + (1.0f - potValue) * (MAX_MAX_SCALE - MIN_MAX_SCALE);
co838_gtvl2 1:06713d1b69cf 52 }