This code is for Ultrasonic HCSR04 with FRDM-KL25Z

Dependencies:   mbed HC_SR04_Ultrasonic_Library

main.cpp

Committer:
mrbhatter
Date:
2019-09-03
Revision:
3:5fb712f78508
Parent:
2:3566c2d1e86b

File content as of revision 3:5fb712f78508:

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

 void dist(int distance)
{
    //put code here to execute when the distance has changed
    printf("Distance %d mm\r\n", distance);
}

ultrasonic mu(PTC, PTC, .1, 1, &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 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.
    }
}