Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
example.cpp@3:31aec950f7dc, 2018-09-14 (annotated)
- Committer:
 - xmwmx
 - Date:
 - Fri Sep 14 10:52:15 2018 +0000
 - Revision:
 - 3:31aec950f7dc
 - Parent:
 - 2:cd0ea77c7d66
 - Child:
 - 4:fe1e9f9c7b33
 
sr501/BH1750/mq-2/dht11
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 | 1:1197997ae0ea | 16 | |
| xmwmx | 1:1197997ae0ea | 17 | while(1) | 
| xmwmx | 1:1197997ae0ea | 18 | { | 
| xmwmx | 1:1197997ae0ea | 19 | /* | 
| xmwmx | 1:1197997ae0ea | 20 | if(x.operator ==(true)) | 
| xmwmx | 1:1197997ae0ea | 21 | { | 
| xmwmx | 1:1197997ae0ea | 22 | usb2pc.printf("get\r\n"); | 
| xmwmx | 1:1197997ae0ea | 23 | while(x.read()){usb2pc.printf("aaaaaaaaaaaaa\r\n");wait(0.1);myled=1;} | 
| xmwmx | 1:1197997ae0ea | 24 | x.reset(); | 
| xmwmx | 1:1197997ae0ea | 25 | } | 
| xmwmx | 1:1197997ae0ea | 26 | |
| xmwmx | 1:1197997ae0ea | 27 | else | 
| xmwmx | 1:1197997ae0ea | 28 | { | 
| xmwmx | 1:1197997ae0ea | 29 | usb2pc.printf("no\r\n"); | 
| xmwmx | 1:1197997ae0ea | 30 | } | 
| xmwmx | 1:1197997ae0ea | 31 | wait(0.1); | 
| xmwmx | 1:1197997ae0ea | 32 | */ | 
| xmwmx | 2:cd0ea77c7d66 | 33 | /* | 
| xmwmx | 1:1197997ae0ea | 34 | float light=y.getlightdata(); | 
| xmwmx | 1:1197997ae0ea | 35 | usb2pc.printf("Light intensity: %.4f Lux\r\n",light); | 
| xmwmx | 2:cd0ea77c7d66 | 36 | */ | 
| xmwmx | 3:31aec950f7dc | 37 | /* | 
| xmwmx | 2:cd0ea77c7d66 | 38 | if(z.operator==(true)) | 
| xmwmx | 2:cd0ea77c7d66 | 39 | { | 
| xmwmx | 2:cd0ea77c7d66 | 40 | usb2pc.printf("mq on\r\n"); | 
| xmwmx | 3:31aec950f7dc | 41 | while(!z.read()){usb2pc.printf("%.3f\r\n",z.getairdata());wait(0.1);myled=1;} | 
| xmwmx | 2:cd0ea77c7d66 | 42 | myled = 1; // LED is ON | 
| xmwmx | 2:cd0ea77c7d66 | 43 | wait(0.2); // 200 ms | 
| xmwmx | 2:cd0ea77c7d66 | 44 | z.reset(); | 
| xmwmx | 2:cd0ea77c7d66 | 45 | } | 
| xmwmx | 2:cd0ea77c7d66 | 46 | else | 
| xmwmx | 2:cd0ea77c7d66 | 47 | { | 
| xmwmx | 2:cd0ea77c7d66 | 48 | usb2pc.printf("mq off\r\n"); | 
| xmwmx | 2:cd0ea77c7d66 | 49 | myled = 0; // LED is OFF | 
| xmwmx | 2:cd0ea77c7d66 | 50 | wait(1.0); // 1 sec | 
| xmwmx | 2:cd0ea77c7d66 | 51 | } | 
| xmwmx | 3:31aec950f7dc | 52 | */ | 
| xmwmx | 3:31aec950f7dc | 53 | ///* | 
| xmwmx | 3:31aec950f7dc | 54 | if(w.getdata()) | 
| xmwmx | 3:31aec950f7dc | 55 | { | 
| xmwmx | 3:31aec950f7dc | 56 | usb2pc.printf("Humidity (%):%.3f\r\n",w.gethumidity()); | 
| xmwmx | 3:31aec950f7dc | 57 | usb2pc.printf("Temperature (oC): %.3f\r\n",w.gettemperature()); | 
| xmwmx | 3:31aec950f7dc | 58 | } | 
| xmwmx | 3:31aec950f7dc | 59 | wait(2); | 
| xmwmx | 3:31aec950f7dc | 60 | //*/ | 
| xmwmx | 1:1197997ae0ea | 61 | } | 
| xmwmx | 1:1197997ae0ea | 62 | } |