You are viewing an older revision! See the latest version
Room temperature control
Write a class named Heater, with the following declaration part:
Heater.h
#ifndef HEATER_H
#define HEATER_H
#include "mbed.h"
/** A simple class for temperature control in the room using
* a heater driven via digital output and one analog temperature sensor.
*
* Author(s): TVZ Mechatronics Team
*
*/
class Heater {
public:
/** Constructor receives pin names of the temperature sensor and
* the PwmOut pin to which the heater driver is connected. */
Heater(PinName sensorPin, PinName pwmoutPin);
/** Set the temperature range of the sensor. */
void configureSensor(float minTemperature, float maxTemperature);
/** Read the current room temperature from the sensor. */
float readTemperature();
/** Get the current room temperature (do not read from sensor again). */
bool isHeaterOn();
/** Set the desired room temperature. */
void setTemperature(float temp);
private:
AnalogIn sensor;
DigitalOut driver;
Ticker ticker;
void regulateTemperature();
bool heaterOn;
float currentTemp, desiredTemp, minTemp, maxTemp, hysteresis, heaterOnTemp, heaterOffTemp;
};
#endif // HEATER_H