Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HCSR04 TextLCD mbed
Fork of TextLCD_HelloWorld by
main.cpp
00001 // Hello World! for the TextLCD 00002 00003 #include "mbed.h" 00004 #include "TextLCD.h" 00005 #include "HCSR04.h" 00006 00007 TextLCD lcd(D12, D11, D5, D4, D3, D2); // rs, e, d4-d7 00008 00009 int main() { 00010 lcd.printf("Distance Calculator."); 00011 wait(1); 00012 lcd.cls(); 00013 lcd.locate(0,0); 00014 HCSR04 sensor(D7,D8); 00015 sensor.setRanges(1,150); 00016 lcd.printf("Min.= %g cm", sensor.getMinRange()); 00017 lcd.locate(0,1); 00018 lcd.printf("Max.= %g cm", sensor.getMaxRange()); 00019 wait(2); 00020 lcd.cls(); 00021 lcd.locate(0,0); 00022 lcd.printf("Distance: "); 00023 while(1) { 00024 lcd.locate(0,1); 00025 lcd.printf("%5.3f cm", sensor.getDistance_cm()); 00026 wait_ms(1000); 00027 lcd.locate(0,1); 00028 lcd.printf(" "); 00029 } 00030 00031 }
Generated on Thu Jul 28 2022 08:01:37 by
1.7.2
