Program to test the ultrasonic sensor

Dependencies:   Ultrasonic mbed

main.cpp

Committer:
AndreaAndreoli
Date:
2016-06-05
Revision:
3:8a9728cee8e0
Parent:
2:ba2b5acf0fdd

File content as of revision 3:8a9728cee8e0:

/*
* An example showing how to use the Ultrasonic library
*/
#include "mbed.h"
#include "Ultrasonic.h"

DigitalOut led(LED_RED);

Serial  pc(USBTX, USBRX); // tx, rx

int main()
{
    Ultrasonic usonic(D2,D4);  // Just call this funtion to initialize the ultrasonic sensor
    while (true) {
        led = !led;
        pc.printf("Distance: %d \n", usonic.read_cm());    // Call read_cm() to get the distance in cm
        wait(0.2);
    }
}