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.
Dependents: Nucleo_UltrasonicHelloWorld xxx_Sonar-HC-SR04_Lsg
Revision 6:9808e2c61247, committed 2021-06-10
- Comitter:
- JohnnyK
- Date:
- Thu Jun 10 18:53:38 2021 +0000
- Parent:
- 5:6fd0e9c7ead4
- Commit message:
- add example into .h
Changed in this revision
| ultrasonic.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ultrasonic.h Thu Jun 10 18:45:59 2021 +0000
+++ b/ultrasonic.h Thu Jun 10 18:53:38 2021 +0000
@@ -1,6 +1,36 @@
#ifndef MBED_ULTRASONIC_H
#define MBED_ULTRASONIC_H
+/**
+ @code
+
+ #include "mbed.h"
+ #include "ultrasonic.h"
+
+ void dist(int distance)
+ {
+ //put code here to happen when the distance is changed
+ printf("Distance changed to %dmm\r\n", distance);
+ }
+
+ ultrasonic mu(D8, D9, 100ms, 1s, &dist); //Set the trigger pin to D8 and the echo pin to D9
+ //have updates every .1 seconds and a timeout after 1
+ //second, and call dist when the distance changes
+
+ int main()
+ {
+ mu.startUpdates();//start mesuring the distance
+ while(1)
+ {
+ //Do something else here
+ mu.checkDistance(); //call checkDistance() as much as possible, as this is where
+ //the class checks if dist needs to be called.
+ }
+ }
+
+ @endcode
+*/
+
#include "mbed.h"
class ultrasonic