Sensore ultrasuoni con LCD
Dependencies: HCSR04 TextLCD mbed
main.cpp@0:0e438c892675, 2016-10-24 (annotated)
- Committer:
- Mattinico
- Date:
- Mon Oct 24 18:05:34 2016 +0000
- Revision:
- 0:0e438c892675
k
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mattinico | 0:0e438c892675 | 1 | // Hello World! for the TextLCD |
Mattinico | 0:0e438c892675 | 2 | |
Mattinico | 0:0e438c892675 | 3 | #include "mbed.h" |
Mattinico | 0:0e438c892675 | 4 | #include "TextLCD.h" |
Mattinico | 0:0e438c892675 | 5 | #include "HCSR04.h" |
Mattinico | 0:0e438c892675 | 6 | |
Mattinico | 0:0e438c892675 | 7 | TextLCD lcd(D12, D11, D5, D4, D3, D2); // rs, e, d4-d7 |
Mattinico | 0:0e438c892675 | 8 | |
Mattinico | 0:0e438c892675 | 9 | int main() { |
Mattinico | 0:0e438c892675 | 10 | lcd.printf("Distance Calculator."); |
Mattinico | 0:0e438c892675 | 11 | wait(1); |
Mattinico | 0:0e438c892675 | 12 | lcd.cls(); |
Mattinico | 0:0e438c892675 | 13 | lcd.locate(0,0); |
Mattinico | 0:0e438c892675 | 14 | HCSR04 sensor(D7,D8); |
Mattinico | 0:0e438c892675 | 15 | sensor.setRanges(1,150); |
Mattinico | 0:0e438c892675 | 16 | lcd.printf("Min.= %g cm", sensor.getMinRange()); |
Mattinico | 0:0e438c892675 | 17 | lcd.locate(0,1); |
Mattinico | 0:0e438c892675 | 18 | lcd.printf("Max.= %g cm", sensor.getMaxRange()); |
Mattinico | 0:0e438c892675 | 19 | wait(2); |
Mattinico | 0:0e438c892675 | 20 | lcd.cls(); |
Mattinico | 0:0e438c892675 | 21 | lcd.locate(0,0); |
Mattinico | 0:0e438c892675 | 22 | lcd.printf("Distance: "); |
Mattinico | 0:0e438c892675 | 23 | while(1) { |
Mattinico | 0:0e438c892675 | 24 | lcd.locate(0,1); |
Mattinico | 0:0e438c892675 | 25 | lcd.printf("%5.3f cm", sensor.getDistance_cm()); |
Mattinico | 0:0e438c892675 | 26 | wait_ms(1000); |
Mattinico | 0:0e438c892675 | 27 | lcd.locate(0,1); |
Mattinico | 0:0e438c892675 | 28 | lcd.printf(" "); |
Mattinico | 0:0e438c892675 | 29 | } |
Mattinico | 0:0e438c892675 | 30 | |
Mattinico | 0:0e438c892675 | 31 | } |