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
main.cpp@1:ccef6d6d9b62, 2016-05-17 (annotated)
- Committer:
- nprobably
- Date:
- Tue May 17 23:38:58 2016 +0000
- Revision:
- 1:ccef6d6d9b62
- Parent:
- 0:671eadfdf703
- Child:
- 2:3d87a559769a
added comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nprobably | 1:ccef6d6d9b62 | 1 | /* mbed Seeed Archlink Temperature Humidity and Servo starter code |
nprobably | 1:ccef6d6d9b62 | 2 | * |
nprobably | 1:ccef6d6d9b62 | 3 | * This program take the temperature humidity reading and writes to the USB serial |
nprobably | 1:ccef6d6d9b62 | 4 | * The servo is actuated for each loop-iteration |
nprobably | 1:ccef6d6d9b62 | 5 | * Fow how to view the serial output, please refer to the mbed serial cookbook: https://developer.mbed.org/handbook/Serial |
nprobably | 1:ccef6d6d9b62 | 6 | * |
nprobably | 1:ccef6d6d9b62 | 7 | * Neil Tan |
nprobably | 1:ccef6d6d9b62 | 8 | */ |
nprobably | 1:ccef6d6d9b62 | 9 | |
nprobably | 1:ccef6d6d9b62 | 10 | |
nprobably | 0:671eadfdf703 | 11 | #include "mbed.h" |
nprobably | 0:671eadfdf703 | 12 | #include "Servo.h" |
nprobably | 0:671eadfdf703 | 13 | #include "DHT22.h" |
nprobably | 0:671eadfdf703 | 14 | |
nprobably | 0:671eadfdf703 | 15 | DigitalOut myled(LED1); |
nprobably | 1:ccef6d6d9b62 | 16 | Servo myservo(p4); //p4 works, using other pins is possible too |
nprobably | 1:ccef6d6d9b62 | 17 | DHT22 sensor(p6); //the pin of the connected grove port |
nprobably | 0:671eadfdf703 | 18 | Serial pc(USBTX, USBRX); |
nprobably | 0:671eadfdf703 | 19 | |
nprobably | 0:671eadfdf703 | 20 | int main() { |
nprobably | 0:671eadfdf703 | 21 | |
nprobably | 0:671eadfdf703 | 22 | bool status; |
nprobably | 0:671eadfdf703 | 23 | pc.printf("\r\nDHT Test program"); |
nprobably | 0:671eadfdf703 | 24 | pc.printf("\r\n******************\r\n"); |
nprobably | 0:671eadfdf703 | 25 | while (1) { |
nprobably | 0:671eadfdf703 | 26 | myled = 1; |
nprobably | 1:ccef6d6d9b62 | 27 | status = sensor.sample(); //returns false if the sensor checksum fails |
nprobably | 0:671eadfdf703 | 28 | if (status) { |
nprobably | 1:ccef6d6d9b62 | 29 | pc.printf("Temperature is %f C \r\n", sensor.getTemperature()/10.0f); //the readings need to be divided by 10 |
nprobably | 0:671eadfdf703 | 30 | pc.printf("Humidity is %f \r\n", sensor.getHumidity()/10.0f); |
nprobably | 0:671eadfdf703 | 31 | } else { |
nprobably | 0:671eadfdf703 | 32 | pc.printf("Error reading sample \r\n"); |
nprobably | 0:671eadfdf703 | 33 | } |
nprobably | 0:671eadfdf703 | 34 | |
nprobably | 0:671eadfdf703 | 35 | myservo = 0.0f; |
nprobably | 0:671eadfdf703 | 36 | wait(5); |
nprobably | 0:671eadfdf703 | 37 | myservo = 1.0f; |
nprobably | 0:671eadfdf703 | 38 | wait(5); |
nprobably | 0:671eadfdf703 | 39 | |
nprobably | 0:671eadfdf703 | 40 | myled = 0; |
nprobably | 0:671eadfdf703 | 41 | } |
nprobably | 0:671eadfdf703 | 42 | } |