![](/media/cache/group/DffTeam_Yf25WvB.jpg.50x50_q85.jpg)
Esercitazione sensore ultrasuoni
Dependencies: HCSR04 TextLCD mbed
Diff: main.cpp
- Revision:
- 0:182c2bb05bb1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Oct 24 10:52:06 2016 +0000 @@ -0,0 +1,28 @@ +#include "mbed.h" +#include "TextLCD.h" +#include "HCSR04.h" +TextLCD lcd(D12, D11, D5, D4, D3, D2, TextLCD::LCD16x2); +DigitalOut myled(LED1); + +int main(){ + lcd.printf("Distance Calculator."); + wait(1); + lcd.cls(); + lcd.locate(0,0); + HCSR04 sensor(D7, D8); //echo pin, trig pin + sensor.setRanges(1, 150); + lcd.printf("Min. = %g cm", sensor.getMinRange()); + lcd.locate(0,1); + lcd.printf("Max. = %g cm",sensor.getMaxRange()); + wait(2); + lcd.cls(); + lcd.locate(0,0); + lcd.printf("Distance: "); + while(1){ + lcd.locate(0,1); + lcd.printf("%5.3f cm", sensor.getDistance_cm()); + wait_ms(1000); + lcd.locate(0,1); + lcd.printf(" "); + } +} \ No newline at end of file