ghj

Dependencies:   HCSR04 TextLCD mbed

Fork of TextLCD_HelloWorld by Simon Ford

main.cpp

Committer:
Mattinico
Date:
2016-10-24
Revision:
3:aef923372d4c
Parent:
2:ad0b044d0a10

File content as of revision 3:aef923372d4c:

// Hello World! for the TextLCD

#include "mbed.h"
#include "TextLCD.h"
#include "HCSR04.h"

TextLCD lcd(D12, D11, D5, D4, D3, D2); // rs, e, d4-d7

int main() {
    lcd.printf("Distance Calculator.");
    wait(1);
    lcd.cls();
    lcd.locate(0,0);
    HCSR04 sensor(D7,D8);
    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("             ");
    }
        
}