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 hcsr04-test-1 by
Diff: main.cpp
- Revision:
- 0:a804a58b647b
- Child:
- 1:8711db3189d0
diff -r 000000000000 -r a804a58b647b main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Mar 20 03:32:56 2018 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+#include "HCSR04.h"
+
+ Serial pc(USBTX,USBRX); // Create a serial connection to pc through the mbed USB cable
+
+ void dist(int distance)
+{
+ //put code here to execute when the distance has changed
+ printf("Distance %d mm\r\n", distance);
+}
+
+HCSR04 sensor(D8,D9);
+DigitalOut Green(LED2);
+
+int main()
+{
+ wait_ms(4000);
+
+int echoVal = sensor.echo_duration();
+ Green = 1;
+
+ while(1){
+ int a = sensor.echo_duration();
+ if (a - echoVal > 75 || echoVal - a > 75){
+ Green=0;
+ wait(.2);
+ Green=1;
+ wait(.2);
+ }
+ pc.printf("%d \n\r",a);
+ wait_ms(50);
+ }
+}
+
