Seeed
/
seeed-grove-dust-sensor-PPD42NS
Seeed Grove Dust Sensor PPD42NS http://wiki.seeed.cc/Grove-Dust_Sensor/
Revision 0:8dd765fb7e02, committed 2018-03-09
- Comitter:
- mbedAustin
- Date:
- Fri Mar 09 06:57:34 2018 +0000
- Commit message:
- Initial Commit
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed-os.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 8dd765fb7e02 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 09 06:57:34 2018 +0000 @@ -0,0 +1,40 @@ +#include "mbed.h" +#include "math.h" + +// Measure duration of time that the signal is low in a 30sec period. + +InterruptIn input(PA_0); // Change your pin name here +Timer t; // measure amount of time signal is low +Ticker m; // every 30 seconds calculate measurement + +// Start Timer +void start(void){ + t.start(); +} + +// Stop TImer +void stop(void){ + t.stop(); +} + +// calculate sensor value +void calculate(){ + // run measurements + int lpo = t.read_us(); + float ratio = t.read_us()/(30000*10.0); + float concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; + printf("\r\nlpo = %d, r = %f, c = %f pcs/0.01cf\r\n",lpo,ratio,concentration); + + // reset and run sensors + t.reset(); // reset mesurement every 30 seconds + input.fall(&start); // start measuring when signal is low + input.rise(&stop); // stop measuring when signal is high +} + +int main(){ + printf("\r\n Starting...\r\n"); + m.attach(&calculate,30.0); // measure for 30 seconds + while(1){ + ; + } +} \ No newline at end of file
diff -r 000000000000 -r 8dd765fb7e02 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Fri Mar 09 06:57:34 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/armmbed/mbed-os/#91e6db1ea251ffcc973001ed90477f42fdca5751