how to control a servo with temp & humidity
Dependencies: DHT22 Servo mbed
Diff: main.cpp
- Revision:
- 2:3d87a559769a
- Parent:
- 1:ccef6d6d9b62
- Child:
- 3:98645a154332
diff -r ccef6d6d9b62 -r 3d87a559769a main.cpp --- a/main.cpp Tue May 17 23:38:58 2016 +0000 +++ b/main.cpp Sat May 28 04:38:45 2016 +0000 @@ -8,27 +8,39 @@ */ -#include "mbed.h" -#include "Servo.h" -#include "DHT22.h" +#include "mbed.h" // this tells us to load mbed related functions +#include "Servo.h" // library for the Servo +#include "DHT22.h" // library for the Temp&Humidity sensor -DigitalOut myled(LED1); -Servo myservo(p4); //p4 works, using other pins is possible too -DHT22 sensor(p6); //the pin of the connected grove port -Serial pc(USBTX, USBRX); +DigitalOut myled(LED1); // used as an output for the sensor +Servo myservo(p4); // p4 works, using other pins is possible too +DHT22 sensor(p6); // the pin of the connected grove port +Serial pc(USBTX, USBRX); // serial TX & RX +// this code runs when the microcontroller starts up int main() { bool status; pc.printf("\r\nDHT Test program"); pc.printf("\r\n******************\r\n"); + + // spin a main loop all the time while (1) { + // turn off the LED myled = 1; - status = sensor.sample(); //returns false if the sensor checksum fails + + // YOUR CODE HERE: get the status of the sensor checksum, sucessful or failed + + + // sensor checksum successful if (status) { + // printf the temperature from the sensor pc.printf("Temperature is %f C \r\n", sensor.getTemperature()/10.0f); //the readings need to be divided by 10 - pc.printf("Humidity is %f \r\n", sensor.getHumidity()/10.0f); - } else { + + // YOUR CODE HERE: printf the humidity from the sensor + + + } else { // sensor checksum failed pc.printf("Error reading sample \r\n"); } @@ -37,6 +49,7 @@ myservo = 1.0f; wait(5); + // turn on the LED myled = 0; } } \ No newline at end of file