Records temperature using TMP36GZ and outputs to HD44780 LCD screen (using tick interrupt routine). Alterable trip level that turns on/off LED with hysteresis. For ST Nucleo F401RE.

Dependencies:   RepeatButton TMP36 GZ TextLCD mbed

Fork of Thermostat_Nucleo by Sapphire

main.cpp

Committer:
MarcoAmerena
Date:
2014-02-26
Revision:
0:f5fbeaf3592c
Child:
1:9bf30974727c

File content as of revision 0:f5fbeaf3592c:

#include "mbed.h"
#include "TextLCD.h"
#include "TMP36GZ.h"
#include "RepeatButton.h"
//#include "InterruptManager.h"
//#include <cstdlib>

using namespace std;
#define REPEAT_DELAY 500
#define REPEAT_PERIOD 100
#define KEY_UP 2
#define KEY_DOWN 4

Ticker tick;
TextLCD lcd(PC_10, PC_12, PA_13, PA_14, PA_15, PB_7); // rs, e, d4-d7
TMP36GZ temp(PA_0);
DigitalOut led(LED1);

KeyBuffer TheKeyBuffer(32);
RepeatButton butUp(PB_4, REPEAT_DELAY, REPEAT_PERIOD, &TheKeyBuffer, KEY_UP);
RepeatButton butDown(PB_3, REPEAT_DELAY, REPEAT_PERIOD, &TheKeyBuffer, KEY_DOWN);

float d, level;

void disp() 
{
    lcd.locate(0, 0); 
    lcd.printf("%3.1f %cC", d, 223);
    lcd.locate(0, 1);
    lcd.printf("Trip %3.1f", level);  
}

int main() 
{
    level = 21.0;  //Trip level is at %f initially
    float leveloff;
    int value;
    
    tick.attach(&disp, 0.5); // setup ticker to call flip after # seconds
    
    while(1) 
    { 
    d = temp.sample();  //Define d and f as temp celsius and fahrenheit
    leveloff = (level - 2);
    
    for(value = TheKeyBuffer.Read(); value != -1; value = TheKeyBuffer.Read()) //Button 1 and Button 3 increase and decrease trip level
    {
        switch(value)
        {
            case KEY_UP:
            level += 0.1;
            break;
                
            case KEY_DOWN:
            level -= 0.1;
            break;
        }
    } 

    if(d >= level)
    {
    led = 1;
    }
    else if(d <= leveloff)
    {
    led = 0;
    } 
    
    } 
}