ECE 4180 / Mbed 2 deprecated 4180Lab3Part1

Dependencies:   mbed 4DGL-uLCD-SE HC_SR04_Ultrasonic_Library

Committer:
khuifang2202
Date:
Sat Feb 16 18:23:14 2019 +0000
Revision:
3:bc11c7809ffd
Parent:
2:3566c2d1e86b
huifang;

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"
khuifang2202 3:bc11c7809ffd 3 #include "uLCD_4DGL.h" //lcd
khuifang2202 3:bc11c7809ffd 4
khuifang2202 3:bc11c7809ffd 5 //lcd
khuifang2202 3:bc11c7809ffd 6 uLCD_4DGL uLCD(p13,p14,p30); // serial tx, serial rx, reset pin;
ejteb 0:1704ea055c4f 7
ejteb 0:1704ea055c4f 8 void dist(int distance)
ejteb 0:1704ea055c4f 9 {
4180_1 2:3566c2d1e86b 10 //put code here to execute when the distance has changed
khuifang2202 3:bc11c7809ffd 11 //uLCD.printf("Distance = %ld ft\r\n", distance);
khuifang2202 3:bc11c7809ffd 12 uLCD.printf("Distance = %d ft\r\n", distance);
khuifang2202 3:bc11c7809ffd 13 //printf("Distance %d mm\r\n", distance);
ejteb 0:1704ea055c4f 14 }
ejteb 0:1704ea055c4f 15
4180_1 2:3566c2d1e86b 16 ultrasonic mu(p6, p7, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9
ejteb 1:4a5586eb1765 17 //have updates every .1 seconds and a timeout after 1
ejteb 1:4a5586eb1765 18 //second, and call dist when the distance changes
ejteb 0:1704ea055c4f 19
ejteb 0:1704ea055c4f 20 int main()
ejteb 0:1704ea055c4f 21 {
4180_1 2:3566c2d1e86b 22 mu.startUpdates();//start measuring the distance
ejteb 0:1704ea055c4f 23 while(1)
ejteb 0:1704ea055c4f 24 {
ejteb 1:4a5586eb1765 25 //Do something else here
ejteb 1:4a5586eb1765 26 mu.checkDistance(); //call checkDistance() as much as possible, as this is where
ejteb 1:4a5586eb1765 27 //the class checks if dist needs to be called.
khuifang2202 3:bc11c7809ffd 28
khuifang2202 3:bc11c7809ffd 29
ejteb 0:1704ea055c4f 30 }
ejteb 0:1704ea055c4f 31 }