Mattia Nicosia / Mbed 2 deprecated TextLCD_HelloWorld

Dependencies:   HCSR04 TextLCD mbed

Fork of TextLCD_HelloWorld by Simon Ford

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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 }