New with OLED Output.
Dependencies: HC_SR04_Ultrasonic_Library OLEDDisplay mbed
Fork of UltraschallSensor by
main.cpp
- Committer:
- dbdata
- Date:
- 2016-10-29
- Revision:
- 1:48e4876a3868
- Parent:
- 0:b84310cad4b3
File content as of revision 1:48e4876a3868:
#include "mbed.h" #include "OLEDDisplay.h" DigitalIn echo( A4 ); DigitalOut trigger( A5 ); Timer t; OLEDDisplay oled; float i; int main() { t.start(); printf(" ===[ Ultrasonic Range ]==="); // OLED Display oled.clear(); while (1) { oled.clear(); oled.printf( "Ultrasonic Range" ); // send pulse trigger=1; wait(0.000004); trigger=0; // wait for the echo line to go high while (!echo); // measure the length of the pulse t.reset(); while (echo); i = t.read_us(); // display result printf("\n\n\rPulselength %6.0f uS",i); oled.printf("\n\rPulselength %6.0f uS",i); i=i/58; printf("\n\n\rDistance %4.0f cm",i); oled.printf("\rDistance %4.0f cm",i); wait(2); } }