A program that demonstrates the development of library, using as an example an ultrasonic distance sensor HC-SR04.

Dependencies:   mbed HCSR04 AutomationElements

main.cpp

Committer:
tbjazic
Date:
2015-12-05
Revision:
2:f86b1e3609b3
Parent:
1:22043b67c31c
Child:
3:3297ea6e3ae1

File content as of revision 2:f86b1e3609b3:

/** Revision 2: Separating the class declaration, implementation and main() function into files.  */

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

Serial pc(USBTX, USBRX);    // communication with terminal

int main() {
    HCSR04 sensor(p5, p7);     // instantiate the sensor object
    while(1) {
         /** Print the result in cm to the terminal with 1 decimal place
         *  (number 5 after % means that total of 5 digits will be reserved
         *  for printing the number, including the dot and one decimal place). */
        pc.printf("Distance: %5.1f cm\r", sensor.getDistance_cm());
        wait_ms(1000-25);
    }
}