Kevin Abraham / Mbed 2 deprecated 4180Lab3-1

Dependencies:   HC_SR04_Ultrasonic_Library mbed

Fork of LPC1768_HCSR04_HelloWorld by jim hamblen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "ultrasonic.h"
00003 
00004  void dist(int distance)
00005 {
00006     //put code here to execute when the distance has changed
00007     printf("Distance %d mm\r\n", distance);
00008 }
00009 
00010 ultrasonic mu(p6, p7, .1, 1, &dist);    //Set the trigger pin to D8 and the echo pin to D9
00011                                         //have updates every .1 seconds and a timeout after 1
00012                                         //second, and call dist when the distance changes
00013 
00014 int main()
00015 {
00016     mu.startUpdates();//start measuring the distance
00017     while(1)
00018     {
00019         //Do something else here
00020         mu.checkDistance();     //call checkDistance() as much as possible, as this is where
00021                                 //the class checks if dist needs to be called.
00022     }
00023 }