sr501/BH1750/mq-2/dht11

Dependencies:   mbed

Fork of sensors_2 by w mx

example.cpp

Committer:
xmwmx
Date:
2018-10-18
Revision:
4:fe1e9f9c7b33
Parent:
3:31aec950f7dc

File content as of revision 4:fe1e9f9c7b33:

#include "sensors.h"
#include "mbed.h"

Serial usb2pc(PA_2, PA_3, 9600);  
DigitalOut myled(PC_13);

int main()
{

    
    usb2pc.printf("starting\r\n");
    sr501 x(PB_1);
    BH1750 y(PB_7,PB_6);
    mq z(PA_7,PA_6);
    dht11 w(PA_5);
    DS18B20 v(PC_14);
    YL u(PA_1,PA_0);
    BMP180 t(PB_9,PB_8);
    GP2Y1010 s(PA_8,PB_0);
    
    while(1)
    {
        /*sr501
        if(x.operator ==(true))
        {
            usb2pc.printf("get\r\n");
            while(x.read()){usb2pc.printf("aaaaaaaaaaaaa\r\n");wait(0.1);myled=1;}
            x.reset();
        }
        
        else
        {
            usb2pc.printf("no\r\n");
        }
        wait(0.1);
        */
        /*BH1750
        float light=y.getlightdata();
        usb2pc.printf("Light intensity: %.4f Lux\r\n",light);
        */
        /*mq
        if(z.operator==(true))
        {
            usb2pc.printf("mq on\r\n");
            while(!z.read()){usb2pc.printf("%.3f\r\n",z.getairdata());wait(0.1);myled=1;}
            myled = 1; // LED is ON
            wait(0.2); // 200 ms
            z.reset();
        }
        else
        {
            usb2pc.printf("mq off\r\n");
            myled = 0; // LED is OFF
            wait(1.0); // 1 sec
        }
        */
        /*dht11
        if(w.getdata())
        {
            usb2pc.printf("Humidity (%):%.3f\r\n",w.gethumidity());
            usb2pc.printf("Temperature (oC): %.3f\r\n",w.gettemperature());
        }
        wait(2);
        */
        /*DS18B20
        if(v.getdata())
        {
            usb2pc.printf("Temperature (oC): %.3f\r\n",v.gettemperature());
        }
        wait(2);
        */
        /*YL-38
        if(u.operator==(true))
        {
            usb2pc.printf("YL on\r\n");
            while(!u.read()){usb2pc.printf("%.3f\r\n",u.getairdata());wait(0.1);myled=1;}
            myled = 1; // LED is ON
            wait(0.2); // 200 ms
            u.reset();
        }
        else
        {
            usb2pc.printf("YL off\r\n");
            myled = 0; // LED is OFF
            wait(1.0); // 1 sec
        }
        */
        /*bmp180
        usb2pc.printf("Temperature is  %.1f C\r\n", (float)t.BMP180GetTemperature()); 
        usb2pc.printf("Pressure is  %.3f kPa\r\n", (float)t.BMP180GetPressure()/1000.0);
        wait(1.0); 
        */
        /*GP2Y1010
        usb2pc.printf("Dust Density: %.3f \r\n",s.getairdata()) ;
        wait(1.0); 
        */
    }
}