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
ThermalDisplayer.cpp@2:5d0c209e5c61, 2016-02-10 (annotated)
- Committer:
- co838_gtvl2
- Date:
- Wed Feb 10 01:01:54 2016 +0000
- Revision:
- 2:5d0c209e5c61
- Parent:
- 1:06713d1b69cf
- Child:
- 3:a4dac093a968
Added scale management using POT 2.
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:5d0c209e5c61 | 25 | * Screen if flusing and flashing everytime but this is the only way to secure data integrity. |
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 | this->lcd->cls(); |
co838_gtvl2 | 1:06713d1b69cf | 32 | int pos = 0; |
co838_gtvl2 | 1:06713d1b69cf | 33 | for (it = this->temperatures.begin(); it != this->temperatures.end(); it++, pos++) { |
co838_gtvl2 | 2:5d0c209e5c61 | 34 | int height = (int) (32 * ((*it) - this->minScale) / (this->maxScale - this->minScale)); |
co838_gtvl2 | 2:5d0c209e5c61 | 35 | this->lcd->rect(pos * 2, height < 0 ? 31 : 32 - height, pos * 2 + 1, 32, 1); |
co838_gtvl2 | 1:06713d1b69cf | 36 | } |
co838_gtvl2 | 2:5d0c209e5c61 | 37 | } |
co838_gtvl2 | 2:5d0c209e5c61 | 38 | |
co838_gtvl2 | 2:5d0c209e5c61 | 39 | /* |
co838_gtvl2 | 2:5d0c209e5c61 | 40 | * Adjust scale of the display according to POT2 |
co838_gtvl2 | 2:5d0c209e5c61 | 41 | */ |
co838_gtvl2 | 2:5d0c209e5c61 | 42 | void ThermalDisplayer::adjustScale() |
co838_gtvl2 | 2:5d0c209e5c61 | 43 | { |
co838_gtvl2 | 2:5d0c209e5c61 | 44 | float potValue = this->pot; |
co838_gtvl2 | 2:5d0c209e5c61 | 45 | |
co838_gtvl2 | 2:5d0c209e5c61 | 46 | this->minScale = MIN_MIN_SCALE + potValue * (MAX_MIN_SCALE - MIN_MIN_SCALE); |
co838_gtvl2 | 2:5d0c209e5c61 | 47 | this->maxScale = MIN_MAX_SCALE + (1.0f - potValue) * (MAX_MAX_SCALE - MIN_MAX_SCALE); |
co838_gtvl2 | 1:06713d1b69cf | 48 | } |