init

Dependencies:   HCSR04 HC_SR04_Ultrasonic_Library Ultrasonic mbed

Committer:
emanuel22e
Date:
Fri Oct 14 19:32:28 2022 +0000
Revision:
0:236e34a7c050
init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emanuel22e 0:236e34a7c050 1 #include "mbed.h"
emanuel22e 0:236e34a7c050 2 #include "ultrasonic.h"
emanuel22e 0:236e34a7c050 3 Serial pc(USBTX, USBRX);
emanuel22e 0:236e34a7c050 4
emanuel22e 0:236e34a7c050 5 void dist(int distance)
emanuel22e 0:236e34a7c050 6 {
emanuel22e 0:236e34a7c050 7 //put code here to execute when the distance has changed
emanuel22e 0:236e34a7c050 8 pc.printf("Distance %d mm\r\n", distance);
emanuel22e 0:236e34a7c050 9 }
emanuel22e 0:236e34a7c050 10
emanuel22e 0:236e34a7c050 11 ultrasonic mu(p6, p7, .1, 1, &dist); //Set the trigger pin to p6 and the echo pin to p7
emanuel22e 0:236e34a7c050 12 //have updates every .1 seconds and a timeout after 1
emanuel22e 0:236e34a7c050 13 //second, and call dist when the distance changes
emanuel22e 0:236e34a7c050 14
emanuel22e 0:236e34a7c050 15 int main()
emanuel22e 0:236e34a7c050 16 {
emanuel22e 0:236e34a7c050 17 mu.startUpdates();//start measuring the distance
emanuel22e 0:236e34a7c050 18 while(1)
emanuel22e 0:236e34a7c050 19 {
emanuel22e 0:236e34a7c050 20 //Do something else here
emanuel22e 0:236e34a7c050 21 mu.checkDistance(); //call checkDistance() as much as possible, as this is where
emanuel22e 0:236e34a7c050 22 //the class checks if dist needs to be called.
emanuel22e 0:236e34a7c050 23 }
emanuel22e 0:236e34a7c050 24 }