Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed 4DGL-uLCD-SE HC_SR04_Ultrasonic_Library
main.cpp
- Committer:
- 4180_1
- Date:
- 2016-09-13
- Revision:
- 2:3566c2d1e86b
- Parent:
- 1:4a5586eb1765
- Child:
- 3:bc11c7809ffd
File content as of revision 2:3566c2d1e86b:
#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(p6, p7, .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.
}
}