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: ThermalDisplayer.cpp
- Revision:
- 2:5d0c209e5c61
- Parent:
- 1:06713d1b69cf
- Child:
- 3:a4dac093a968
diff -r 06713d1b69cf -r 5d0c209e5c61 ThermalDisplayer.cpp --- a/ThermalDisplayer.cpp Tue Feb 09 21:41:48 2016 +0000 +++ b/ThermalDisplayer.cpp Wed Feb 10 01:01:54 2016 +0000 @@ -1,24 +1,48 @@ #include "ThermalDisplayer.h" -ThermalDisplayer::ThermalDisplayer() { - this->lcd = new C12832(D11, D13, D12, D7, D10); - this->pot = new AnalogIn(A1); - this->temperatures = std::list<float>(MAX_SIZE); +/* + * Constructor, initialize Potentiometer, LCD and variables + */ +ThermalDisplayer::ThermalDisplayer(): pot(A1) +{ + this->lcd = new C12832(D11, D13, D12, D7, D10); + this->temperatures = std::list<float>(MAX_SIZE); + this->minScale = MIN_MIN_SCALE; + this->maxScale = MAX_MAX_SCALE; } -void ThermalDisplayer::addTemp(const float &temp) { +/* + * Add record to temperature historic + */ +void ThermalDisplayer::addTemp(const float &temp) +{ this->temperatures.pop_front(); this->temperatures.push_back(temp); } -void ThermalDisplayer::display() { +/* + * Display informations to the LCD screen + * Screen if flusing and flashing everytime but this is the only way to secure data integrity. + */ +void ThermalDisplayer::display() +{ list<float>::const_iterator it; - + this->lcd->cls(); int pos = 0; for (it = this->temperatures.begin(); it != this->temperatures.end(); it++, pos++) { - float tmp = *it; - - this->lcd->rect(pos * 2, 32, pos * 2 + 1, 32 - (int) (tmp * 32.0 / 50.0), 1); + int height = (int) (32 * ((*it) - this->minScale) / (this->maxScale - this->minScale)); + this->lcd->rect(pos * 2, height < 0 ? 31 : 32 - height, pos * 2 + 1, 32, 1); } +} + +/* + * Adjust scale of the display according to POT2 + */ +void ThermalDisplayer::adjustScale() +{ + float potValue = this->pot; + + this->minScale = MIN_MIN_SCALE + potValue * (MAX_MIN_SCALE - MIN_MIN_SCALE); + this->maxScale = MIN_MAX_SCALE + (1.0f - potValue) * (MAX_MAX_SCALE - MIN_MAX_SCALE); } \ No newline at end of file