homework 7
Dependencies: mbed-rtos mbed C12832_lcd LM75B
Diff: main.cpp
- Revision:
- 95:7e391a5951d1
- Parent:
- 94:551b1df4b10c
- Child:
- 96:c8b0f29d9758
diff -r 551b1df4b10c -r 7e391a5951d1 main.cpp --- a/main.cpp Thu Sep 12 18:46:43 2013 +0000 +++ b/main.cpp Thu Sep 12 19:01:21 2013 +0000 @@ -630,8 +630,13 @@ void temperatureThread(void const *args) // temperature measurement. { int dTempControl = 0; // temperature control. + int dCurrentTimerMs; + int dPreviousTimerMs; osEvent queueEvent; // from button state manager. + dCurrentTimerMs = 0; + dPreviousTimerMs = 0; + temperatureTimer.start(); while(1) // thread loop. @@ -644,15 +649,25 @@ } if (dTempControl == TEMP_READ) - gfCelsius = temperature.read(); // physical measurement. + { + gfCelsius = temperature.read(); // physical measurement. + temperatureTimer.reset(); // reset timer while we're not using it. + } if (dTempControl == TEMP_CALC) { - if (temperatureTimer.read() > 1) + // fetch current timer mS. + dCurrentTimerMs = temperatureTimer.read_ms(); + + // if its been one second, + // synthesize new temperature. + if ((dCurrentTimerMs - dPreviousTimerMs) >= 1000) { - temperatureTimer.reset(); - gfCelsius += (1.0 / 6.0); + gfCelsius += (1.0 / 6.0); + + dPreviousTimerMs = dCurrentTimerMs; // pipeline variable. } + }