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:
- 4:5bf99eb2d740
- Parent:
- 3:a4dac093a968
- Child:
- 6:6c61186c8739
diff -r a4dac093a968 -r 5bf99eb2d740 ThermalDisplayer.cpp --- a/ThermalDisplayer.cpp Wed Feb 10 01:41:39 2016 +0000 +++ b/ThermalDisplayer.cpp Wed Feb 10 16:48:55 2016 +0000 @@ -3,12 +3,15 @@ /* * Constructor, initialize Potentiometer, LCD and variables */ -ThermalDisplayer::ThermalDisplayer(): pot(A1) +ThermalDisplayer::ThermalDisplayer(): pot(A1), accel(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1) { this->lcd = new C12832(D11, D13, D12, D7, D10); + this->lcd->set_auto_up(0); this->temperatures = std::list<float>(MAX_SIZE); this->minScale = MIN_MIN_SCALE; this->maxScale = MAX_MAX_SCALE; + this->screenOrientation = true; + this->accel.enable(); } /* @@ -31,22 +34,39 @@ int pos = 0; for (it = this->temperatures.begin(); it != this->temperatures.end(); it++, pos++) { int height = (int) (32 * ((*it) - this->minScale) / (this->maxScale - this->minScale)); + height = height > DISPLAY_Y ? DISPLAY_Y : (height < 0 ? 0 : height); /* * Draw a white rectangle to erase previous data. - * Then, draw again. + * Then, draw on top of it the new data. */ - this->lcd->rect(pos * 2, 0, pos * 2 + 1, 32, 0); - this->lcd->rect(pos * 2, height < 0 ? 31 : 32 - height, pos * 2 + 1, 32, 1); + if (this->screenOrientation) { + this->lcd->rect(pos * 2, 0, pos * 2 + 1, DISPLAY_Y, 0); + this->lcd->rect(pos * 2, DISPLAY_Y - height, pos * 2 + 1, DISPLAY_Y, 1); + } else { + this->lcd->rect(DISPLAY_X - (pos * 2), 0, DISPLAY_X - (pos * 2 + 1), DISPLAY_Y, 0); + this->lcd->rect(DISPLAY_X - (pos * 2), 0, DISPLAY_X - (pos * 2 + 1), height, 1); + } } + this->lcd->copy_to_lcd(); } /* * Adjust scale of the display according to POT2 + * Also adjust the screen orientation accodring to FXOS8700CQ accelerometer */ -void ThermalDisplayer::adjustScale() +void ThermalDisplayer::adjustScale(Serial &host) { 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); + + SRAWDATA accel_data; + SRAWDATA magn_data; + uint8_t data = this->accel.get_data(&accel_data, &magn_data); + if (accel_data.y <= -100) { + this->screenOrientation = false; + } else { + this->screenOrientation = true; + } } \ No newline at end of file