New with OLED Output.
Dependencies: HC_SR04_Ultrasonic_Library OLEDDisplay mbed
Fork of UltraschallSensor by
main.cpp
00001 #include "mbed.h" 00002 #include "OLEDDisplay.h" 00003 00004 DigitalIn echo( A4 ); 00005 DigitalOut trigger( A5 ); 00006 Timer t; 00007 OLEDDisplay oled; 00008 00009 float i; 00010 00011 int main() 00012 { 00013 t.start(); 00014 printf(" ===[ Ultrasonic Range ]==="); 00015 00016 // OLED Display 00017 oled.clear(); 00018 00019 while (1) 00020 { 00021 oled.clear(); 00022 oled.printf( "Ultrasonic Range" ); 00023 00024 // send pulse 00025 trigger=1; 00026 wait(0.000004); 00027 trigger=0; 00028 00029 // wait for the echo line to go high 00030 while (!echo); 00031 00032 // measure the length of the pulse 00033 t.reset(); 00034 while (echo); 00035 i = t.read_us(); 00036 00037 // display result 00038 printf("\n\n\rPulselength %6.0f uS",i); 00039 oled.printf("\n\rPulselength %6.0f uS",i); 00040 i=i/58; 00041 printf("\n\n\rDistance %4.0f cm",i); 00042 oled.printf("\rDistance %4.0f cm",i); 00043 wait(2); 00044 } 00045 }
Generated on Fri Jul 15 2022 00:12:42 by 1.7.2