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.
Dependencies: DHT22 Servo mbed
Fork of Program4_ServoWithTempAndHumidity by
Diff: main.cpp
- Revision:
- 1:ccef6d6d9b62
- Parent:
- 0:671eadfdf703
- Child:
- 2:3d87a559769a
--- a/main.cpp Tue May 17 16:03:36 2016 +0000 +++ b/main.cpp Tue May 17 23:38:58 2016 +0000 @@ -1,10 +1,20 @@ +/* mbed Seeed Archlink Temperature Humidity and Servo starter code + * + * This program take the temperature humidity reading and writes to the USB serial + * The servo is actuated for each loop-iteration + * Fow how to view the serial output, please refer to the mbed serial cookbook: https://developer.mbed.org/handbook/Serial + * + * Neil Tan + */ + + #include "mbed.h" #include "Servo.h" #include "DHT22.h" DigitalOut myled(LED1); -Servo myservo(p4); -DHT22 sensor(p6); +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); int main() { @@ -14,9 +24,9 @@ pc.printf("\r\n******************\r\n"); while (1) { myled = 1; - status = sensor.sample(); + status = sensor.sample(); //returns false if the sensor checksum fails if (status) { - pc.printf("Temperature is %f C \r\n", sensor.getTemperature()/10.0f); + 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 { pc.printf("Error reading sample \r\n");