how to control a servo with temp & humidity

Dependencies:   DHT22 Servo mbed

main.cpp

Committer:
Maggie17
Date:
2016-05-28
Revision:
2:3d87a559769a
Parent:
1:ccef6d6d9b62
Child:
3:98645a154332

File content as of revision 2:3d87a559769a:

/* 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(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;
        
        // 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
            
            // YOUR CODE HERE: printf the humidity from the sensor
            
            
        } 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;
    }
}