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.
Diff: main.cpp
- Revision:
- 0:64fe0ebc42c6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Nov 11 22:04:30 2020 +0000 @@ -0,0 +1,47 @@ +#include "mbed.h" +#include "DistanceSensor.h" +#include "Plotting.h" + +//To plot with usb, set as below. +Serial pc(USBTX,USBRX); // Tx, Rx Pin +Plotting plot; + +//Set each gpio to see the output of the psd sensor as a led +DistanceSensor pir (p20); + +//Interrupt is generated every 1ms and degree is increased by 1 +unsigned int uiFlag_50ms = 0; + +void counter_1ms () +{ + uiFlag_50ms++; +} + +// Plot distance sensor +int main() +{ + wait(1); + + //Set the 1ms thicker. + Ticker ticker_1ms; + ticker_1ms.attach(&counter_1ms,0.001); + + Timer time; + time.start(); + + while(1) { + // Every 50 ms, + if(uiFlag_50ms>=50) { + uiFlag_50ms=0; + + // clear plotting buffer + plot.reset(); + + // put data to buffer + plot.put(pir.getDistance_cm(),0); + + // send buffer + plot.send(&pc); + } + } +} \ No newline at end of file