znrobotics 智能工场 / Mbed 2 deprecated Seeed_Arch_link_ServoWithTempAndHumidity

Dependencies:   DHT22 Servo mbed

Fork of Program4_ServoWithTempAndHumidity by Robotics Kit Workshop

main.cpp

Committer:
nprobably
Date:
2016-05-17
Revision:
1:ccef6d6d9b62
Parent:
0:671eadfdf703
Child:
2:3d87a559769a

File content as of revision 1:ccef6d6d9b62:

/* 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);  //p4 works, using other pins is possible too
DHT22 sensor(p6);   //the pin of the connected grove port
Serial pc(USBTX, USBRX);
 
int main() {

    bool status;
    pc.printf("\r\nDHT Test program");
    pc.printf("\r\n******************\r\n");
    while (1) {
        myled = 1;
        status = sensor.sample();  //returns false if the sensor checksum fails
        if (status) {
            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");
        }
        
        myservo = 0.0f;
        wait(5);
        myservo = 1.0f;
        wait(5);
        
        myled = 0;
    }
}