w mx
/
sensors3
sr501/BH1750/mq-2/dht11
Fork of sensors_2 by
example.cpp@4:fe1e9f9c7b33, 2018-10-18 (annotated)
- Committer:
- xmwmx
- Date:
- Thu Oct 18 16:23:13 2018 +0000
- Revision:
- 4:fe1e9f9c7b33
- Parent:
- 3:31aec950f7dc
9 kinds of sensors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xmwmx | 1:1197997ae0ea | 1 | #include "sensors.h" |
xmwmx | 1:1197997ae0ea | 2 | #include "mbed.h" |
xmwmx | 1:1197997ae0ea | 3 | |
xmwmx | 1:1197997ae0ea | 4 | Serial usb2pc(PA_2, PA_3, 9600); |
xmwmx | 1:1197997ae0ea | 5 | DigitalOut myled(PC_13); |
xmwmx | 1:1197997ae0ea | 6 | |
xmwmx | 1:1197997ae0ea | 7 | int main() |
xmwmx | 1:1197997ae0ea | 8 | { |
xmwmx | 1:1197997ae0ea | 9 | |
xmwmx | 1:1197997ae0ea | 10 | |
xmwmx | 1:1197997ae0ea | 11 | usb2pc.printf("starting\r\n"); |
xmwmx | 1:1197997ae0ea | 12 | sr501 x(PB_1); |
xmwmx | 1:1197997ae0ea | 13 | BH1750 y(PB_7,PB_6); |
xmwmx | 2:cd0ea77c7d66 | 14 | mq z(PA_7,PA_6); |
xmwmx | 3:31aec950f7dc | 15 | dht11 w(PA_5); |
xmwmx | 4:fe1e9f9c7b33 | 16 | DS18B20 v(PC_14); |
xmwmx | 4:fe1e9f9c7b33 | 17 | YL u(PA_1,PA_0); |
xmwmx | 4:fe1e9f9c7b33 | 18 | BMP180 t(PB_9,PB_8); |
xmwmx | 4:fe1e9f9c7b33 | 19 | GP2Y1010 s(PA_8,PB_0); |
xmwmx | 1:1197997ae0ea | 20 | |
xmwmx | 1:1197997ae0ea | 21 | while(1) |
xmwmx | 1:1197997ae0ea | 22 | { |
xmwmx | 4:fe1e9f9c7b33 | 23 | /*sr501 |
xmwmx | 1:1197997ae0ea | 24 | if(x.operator ==(true)) |
xmwmx | 1:1197997ae0ea | 25 | { |
xmwmx | 1:1197997ae0ea | 26 | usb2pc.printf("get\r\n"); |
xmwmx | 1:1197997ae0ea | 27 | while(x.read()){usb2pc.printf("aaaaaaaaaaaaa\r\n");wait(0.1);myled=1;} |
xmwmx | 1:1197997ae0ea | 28 | x.reset(); |
xmwmx | 1:1197997ae0ea | 29 | } |
xmwmx | 1:1197997ae0ea | 30 | |
xmwmx | 1:1197997ae0ea | 31 | else |
xmwmx | 1:1197997ae0ea | 32 | { |
xmwmx | 1:1197997ae0ea | 33 | usb2pc.printf("no\r\n"); |
xmwmx | 1:1197997ae0ea | 34 | } |
xmwmx | 1:1197997ae0ea | 35 | wait(0.1); |
xmwmx | 1:1197997ae0ea | 36 | */ |
xmwmx | 4:fe1e9f9c7b33 | 37 | /*BH1750 |
xmwmx | 1:1197997ae0ea | 38 | float light=y.getlightdata(); |
xmwmx | 1:1197997ae0ea | 39 | usb2pc.printf("Light intensity: %.4f Lux\r\n",light); |
xmwmx | 2:cd0ea77c7d66 | 40 | */ |
xmwmx | 4:fe1e9f9c7b33 | 41 | /*mq |
xmwmx | 2:cd0ea77c7d66 | 42 | if(z.operator==(true)) |
xmwmx | 2:cd0ea77c7d66 | 43 | { |
xmwmx | 2:cd0ea77c7d66 | 44 | usb2pc.printf("mq on\r\n"); |
xmwmx | 3:31aec950f7dc | 45 | while(!z.read()){usb2pc.printf("%.3f\r\n",z.getairdata());wait(0.1);myled=1;} |
xmwmx | 2:cd0ea77c7d66 | 46 | myled = 1; // LED is ON |
xmwmx | 2:cd0ea77c7d66 | 47 | wait(0.2); // 200 ms |
xmwmx | 2:cd0ea77c7d66 | 48 | z.reset(); |
xmwmx | 2:cd0ea77c7d66 | 49 | } |
xmwmx | 2:cd0ea77c7d66 | 50 | else |
xmwmx | 2:cd0ea77c7d66 | 51 | { |
xmwmx | 2:cd0ea77c7d66 | 52 | usb2pc.printf("mq off\r\n"); |
xmwmx | 2:cd0ea77c7d66 | 53 | myled = 0; // LED is OFF |
xmwmx | 2:cd0ea77c7d66 | 54 | wait(1.0); // 1 sec |
xmwmx | 2:cd0ea77c7d66 | 55 | } |
xmwmx | 3:31aec950f7dc | 56 | */ |
xmwmx | 4:fe1e9f9c7b33 | 57 | /*dht11 |
xmwmx | 3:31aec950f7dc | 58 | if(w.getdata()) |
xmwmx | 3:31aec950f7dc | 59 | { |
xmwmx | 3:31aec950f7dc | 60 | usb2pc.printf("Humidity (%):%.3f\r\n",w.gethumidity()); |
xmwmx | 3:31aec950f7dc | 61 | usb2pc.printf("Temperature (oC): %.3f\r\n",w.gettemperature()); |
xmwmx | 3:31aec950f7dc | 62 | } |
xmwmx | 3:31aec950f7dc | 63 | wait(2); |
xmwmx | 4:fe1e9f9c7b33 | 64 | */ |
xmwmx | 4:fe1e9f9c7b33 | 65 | /*DS18B20 |
xmwmx | 4:fe1e9f9c7b33 | 66 | if(v.getdata()) |
xmwmx | 4:fe1e9f9c7b33 | 67 | { |
xmwmx | 4:fe1e9f9c7b33 | 68 | usb2pc.printf("Temperature (oC): %.3f\r\n",v.gettemperature()); |
xmwmx | 4:fe1e9f9c7b33 | 69 | } |
xmwmx | 4:fe1e9f9c7b33 | 70 | wait(2); |
xmwmx | 4:fe1e9f9c7b33 | 71 | */ |
xmwmx | 4:fe1e9f9c7b33 | 72 | /*YL-38 |
xmwmx | 4:fe1e9f9c7b33 | 73 | if(u.operator==(true)) |
xmwmx | 4:fe1e9f9c7b33 | 74 | { |
xmwmx | 4:fe1e9f9c7b33 | 75 | usb2pc.printf("YL on\r\n"); |
xmwmx | 4:fe1e9f9c7b33 | 76 | while(!u.read()){usb2pc.printf("%.3f\r\n",u.getairdata());wait(0.1);myled=1;} |
xmwmx | 4:fe1e9f9c7b33 | 77 | myled = 1; // LED is ON |
xmwmx | 4:fe1e9f9c7b33 | 78 | wait(0.2); // 200 ms |
xmwmx | 4:fe1e9f9c7b33 | 79 | u.reset(); |
xmwmx | 4:fe1e9f9c7b33 | 80 | } |
xmwmx | 4:fe1e9f9c7b33 | 81 | else |
xmwmx | 4:fe1e9f9c7b33 | 82 | { |
xmwmx | 4:fe1e9f9c7b33 | 83 | usb2pc.printf("YL off\r\n"); |
xmwmx | 4:fe1e9f9c7b33 | 84 | myled = 0; // LED is OFF |
xmwmx | 4:fe1e9f9c7b33 | 85 | wait(1.0); // 1 sec |
xmwmx | 4:fe1e9f9c7b33 | 86 | } |
xmwmx | 4:fe1e9f9c7b33 | 87 | */ |
xmwmx | 4:fe1e9f9c7b33 | 88 | /*bmp180 |
xmwmx | 4:fe1e9f9c7b33 | 89 | usb2pc.printf("Temperature is %.1f C\r\n", (float)t.BMP180GetTemperature()); |
xmwmx | 4:fe1e9f9c7b33 | 90 | usb2pc.printf("Pressure is %.3f kPa\r\n", (float)t.BMP180GetPressure()/1000.0); |
xmwmx | 4:fe1e9f9c7b33 | 91 | wait(1.0); |
xmwmx | 4:fe1e9f9c7b33 | 92 | */ |
xmwmx | 4:fe1e9f9c7b33 | 93 | /*GP2Y1010 |
xmwmx | 4:fe1e9f9c7b33 | 94 | usb2pc.printf("Dust Density: %.3f \r\n",s.getairdata()) ; |
xmwmx | 4:fe1e9f9c7b33 | 95 | wait(1.0); |
xmwmx | 4:fe1e9f9c7b33 | 96 | */ |
xmwmx | 1:1197997ae0ea | 97 | } |
xmwmx | 1:1197997ae0ea | 98 | } |