znrobotics 智能工场 / Mbed 2 deprecated Seeed_Arch_link_ServoWithTempAndHumidity

Dependencies:   DHT22 Servo mbed

Fork of Program4_ServoWithTempAndHumidity by Robotics Kit Workshop

main.cpp

Committer:
Maggie17
Date:
2016-05-28
Revision:
4:c778b9ed6508
Parent:
3:98645a154332
Child:
5:86adb825bfd2

File content as of revision 4:c778b9ed6508:

/* 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"   // 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);  // used as an output for the sensor
Servo myservo(p10);       // p10 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;
        
        // YOUR CODE HERE: get the status of the sensor checksum, successful or failed
        
        
        // sensor checksum successful
        if (status) {
            // printf the temperature and humidity 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 {  // sensor checksum failed
            pc.printf("Error reading sample \r\n");
        }
        
        myservo = 0.0f;
        wait(5);
        myservo = 1.0f;
        wait(5);
        
        // turn on the LED
        myled = 0;
    }
}