Dependencies:   mbed HC_SR04_Ultrasonic_Library

Committer:
michaelveloo
Date:
Sun Sep 26 11:10:10 2021 +0000
Revision:
2:fb993dbcbbb0
Parent:
1:4a5586eb1765
25 Sept Lab for Ultrasonic

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ejteb 0:1704ea055c4f 1 #include "mbed.h"
ejteb 0:1704ea055c4f 2 #include "ultrasonic.h"
ejteb 0:1704ea055c4f 3
ejteb 0:1704ea055c4f 4 void dist(int distance)
ejteb 0:1704ea055c4f 5 {
michaelveloo 2:fb993dbcbbb0 6 //Displays when the distance is changed
ejteb 1:4a5586eb1765 7 printf("Distance changed to %dmm\r\n", distance);
ejteb 0:1704ea055c4f 8 }
ejteb 0:1704ea055c4f 9
michaelveloo 2:fb993dbcbbb0 10 ultrasonic mu(D8, D9, .1, 1, &dist); //Sets the trigger pin to p8 and the echo pin to p9
ejteb 1:4a5586eb1765 11 //have updates every .1 seconds and a timeout after 1
ejteb 1:4a5586eb1765 12 //second, and call dist when the distance changes
ejteb 0:1704ea055c4f 13
ejteb 0:1704ea055c4f 14 int main()
ejteb 0:1704ea055c4f 15 {
ejteb 1:4a5586eb1765 16 mu.startUpdates();//start mesuring the distance
ejteb 0:1704ea055c4f 17 while(1)
ejteb 0:1704ea055c4f 18 {
michaelveloo 2:fb993dbcbbb0 19
ejteb 1:4a5586eb1765 20 mu.checkDistance(); //call checkDistance() as much as possible, as this is where
ejteb 1:4a5586eb1765 21 //the class checks if dist needs to be called.
ejteb 0:1704ea055c4f 22 }
ejteb 0:1704ea055c4f 23 }