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