HC SR04

Dependencies:   mbed HC_SR04_Ultrasonic_Library

main.cpp

Committer:
Batoch
Date:
2019-05-03
Revision:
0:97403de5e127
Child:
1:b47bfaaa417a

File content as of revision 0:97403de5e127:

#include "ultrasonic.h"
#include "mbed.h"


void dist(int distance)
{
    //put code here to execute when the distance has changed
    printf("Distance %d mm\r\n", distance);
}
 
ultrasonic mu(D6, D5, .1, 1, &dist);    //Set the trigger pin to p6 and the echo pin to p5
                                        //have updates every .1 seconds and a timeout after 1
                                        //second, and call dist when the distance changes

int main()
{
    mu.startUpdates();//start measuring 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.
    }
}