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.
Fork of SRF02v_ by
Diff: main.cpp
- Revision:
- 4:3f31934daa52
diff -r eb436c3ca9d1 -r 3f31934daa52 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Dec 09 10:15:16 2015 +0000 @@ -0,0 +1,30 @@ +#include "mbed.h" +#include "SRF02.h" +#include "USBSerial.h" + +SRF02 sensor(p28,p27); +Serial _serial_(USBTX, USBRX); // tx, rx +USBSerial serial; +DigitalIn sw8(p8); + + +int main() { + bool onoff=false; + sw8.mode(PullUp); + //serial.baud(9600); + while(1) { + if(onoff){ + // read sensor distance in cm and print over serial port + int distance = sensor.getDistanceCm(); + serial.printf("Distance = %d cm\n",distance); + _serial_.printf("Distance = %d cm\n",distance); + // short delay before next measurement + if(!sw8){onoff=false;} + wait(0.060); + }else{ + if(!sw8){onoff=true;} + } + wait(0.005); + } + /*return 0;*/ +} \ No newline at end of file