A hello world program for the HC-SR04

Dependencies:   HC_SR04_Ultrasonic_Library mbed

Committer:
ejteb
Date:
Sun Nov 23 20:27:21 2014 +0000
Revision:
0:1704ea055c4f
Child:
1:4a5586eb1765
seems to work :0

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 //time_t startTime;
ejteb 0:1704ea055c4f 5 //Timer t;
ejteb 0:1704ea055c4f 6 //float s;
ejteb 0:1704ea055c4f 7 void dist(int distance)
ejteb 0:1704ea055c4f 8 {
ejteb 0:1704ea055c4f 9 //float new_s;
ejteb 0:1704ea055c4f 10 //new_s = t.read ();
ejteb 0:1704ea055c4f 11 //printf("I think %f s passed, current time %f, %f\r\n", (double)(new_s-s), new_s, s);
ejteb 0:1704ea055c4f 12 //printf("distance updated %d\r\n", distance);
ejteb 0:1704ea055c4f 13 //printf("RTC clock says %d\r\n", (time(NULL)-startTime));
ejteb 0:1704ea055c4f 14 }
ejteb 0:1704ea055c4f 15 void startTimer()
ejteb 0:1704ea055c4f 16 {
ejteb 0:1704ea055c4f 17 //s = t.read();
ejteb 0:1704ea055c4f 18 //printf("timer started \r\n");
ejteb 0:1704ea055c4f 19 //startTime = time(NULL);
ejteb 0:1704ea055c4f 20 }
ejteb 0:1704ea055c4f 21 void trigger()
ejteb 0:1704ea055c4f 22 {
ejteb 0:1704ea055c4f 23 //printf("trigger sent\r\n");
ejteb 0:1704ea055c4f 24 }
ejteb 0:1704ea055c4f 25
ejteb 0:1704ea055c4f 26 ultrasonic mu(D8, D9, 1, 2, &dist, &trigger, &startTimer);
ejteb 0:1704ea055c4f 27
ejteb 0:1704ea055c4f 28 int main()
ejteb 0:1704ea055c4f 29 {
ejteb 0:1704ea055c4f 30 //t.start();
ejteb 0:1704ea055c4f 31 mu.startUpdates();
ejteb 0:1704ea055c4f 32 while(1)
ejteb 0:1704ea055c4f 33 {
ejteb 0:1704ea055c4f 34 //Do something else
ejteb 0:1704ea055c4f 35 //printf("doing something");
ejteb 0:1704ea055c4f 36 if(mu.isUpdated())
ejteb 0:1704ea055c4f 37 {
ejteb 0:1704ea055c4f 38 printf("Distance = %d\r\n", mu.getCurrentDistance());
ejteb 0:1704ea055c4f 39 }
ejteb 0:1704ea055c4f 40 }
ejteb 0:1704ea055c4f 41 }