For CW1

Dependencies:   mbed HC_SR04_Ultrasonic_Library

main.cpp

Committer:
michaelveloo
Date:
2021-09-26
Revision:
0:4fbd246540da

File content as of revision 0:4fbd246540da:

#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(p8, p9, .1, 1, &dist);     //Set the trigger pin to p8 and the echo pin to p9
                                         //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)
     {
         mu.checkDistance(); //call checkDistance() as much as possible, as this is where
                             //the class checks if dist needs to be called. 
     }
}