Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- Maggie17
- Date:
- 2016-05-28
- Revision:
- 2:90b2eb3d14e6
- Parent:
- 0:c12c28a0f9e7
- Child:
- 3:f215a9bec026
File content as of revision 2:90b2eb3d14e6:
#include "mbed.h" // this tells us to load mbed related functions #include "DHT.h" // library for the Temp&Humidity sensor DHT sensor(D4, DHT11); // used as an ouput for the sensor // this code runs when the microcontroller starts up int main() { int error = 0; float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f; // spin a main loop all the time while(1) { wait(2.0f); // read data from the sensor error = sensor.readData(); // read successfully if (0 == error) { // read the temperature in CELCIUS c = sensor.ReadTemperature(CELCIUS); // YOUR CODE HERE: read the temperature in FARENHEIT // YOUR CODE HERE: read the temperature in KELVIN // read the humidity and do the calculation h = sensor.ReadHumidity(); dp = sensor.CalcdewPoint(c, h); dpf = sensor.CalcdewPointFast(c, h); // printf the temperature in Kelvin, Celcius and Farenheit printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f); // YOUR CODE HERE: printf the humidity, dewpoint and dewpoint fast } else { // read unseccessfully printf("Error: %d\n", error); } } }