
ch5_mbed_dust_sensor
Revision 0:859e0fd616ee, committed 2015-01-26
- Comitter:
- mbedschool
- Date:
- Mon Jan 26 09:10:53 2015 +0000
- Commit message:
- ch5_mbed_dust_sensor
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 859e0fd616ee main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Jan 26 09:10:53 2015 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" + +Serial pc(USBTX, USBRX); +InterruptIn probe(p19); +DigitalOut led(LED1); + +Timer timer; +Ticker ticker; + +uint32_t low_time = 0; + +void down(); +void up(); + +void tick() +{ + pc.printf("%d us, %f %%\r\n", low_time, low_time / (30.0 * 1000000)); + low_time = 0; +} + +void down() +{ + probe.rise(&up); + led = 0; + timer.start(); +} + +void up() +{ + led = 1; + timer.stop(); + probe.fall(&down); + + low_time += timer.read_us(); + timer.reset(); +} + +int main() +{ + pc.baud(115200); + pc.printf("Dust Sensor test\r\n"); + probe.fall(&down); + ticker.attach(tick, 30); +} \ No newline at end of file
diff -r 000000000000 -r 859e0fd616ee mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Jan 26 09:10:53 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file