sr501+BH1750+mq

Dependencies:   mbed

Fork of sensors by w mx

example.cpp

Committer:
xmwmx
Date:
2018-09-14
Revision:
3:31aec950f7dc
Parent:
2:cd0ea77c7d66

File content as of revision 3:31aec950f7dc:

#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);
    
    while(1)
    {
        /*
        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);
        */
        /*
        float light=y.getlightdata();
        usb2pc.printf("Light intensity: %.4f Lux\r\n",light);
        */
        /*
        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
        }
        */
        ///*
        if(w.getdata())
        {
            usb2pc.printf("Humidity (%):%.3f\r\n",w.gethumidity());
            usb2pc.printf("Temperature (oC): %.3f\r\n",w.gettemperature());
        }
        wait(2);
        //*/
    }
}