Hello world for utilizing the Lidarlitev2 for distance measurements with the continuos reading setup
Dependencies: LidarLitev2 mbed
main.cpp@0:efca88a80223, 2015-10-22 (annotated)
- Committer:
- sventura3
- Date:
- Thu Oct 22 22:32:02 2015 +0000
- Revision:
- 0:efca88a80223
comitted
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sventura3 | 0:efca88a80223 | 1 | #include "LidarLitev2.h" |
sventura3 | 0:efca88a80223 | 2 | |
sventura3 | 0:efca88a80223 | 3 | LidarLitev2 Lidar(p28, p27);// Instantiate the LidarLitev2 with name Lidar and I2C pin (SDA, SCL) |
sventura3 | 0:efca88a80223 | 4 | Serial pc(USBTX,USBRX); // Create a serial connection to pc through the mbed USB cable |
sventura3 | 0:efca88a80223 | 5 | DigitalIn pinMode(p24); // This pin is to detect the mode out of the lidar in continous mode |
sventura3 | 0:efca88a80223 | 6 | |
sventura3 | 0:efca88a80223 | 7 | |
sventura3 | 0:efca88a80223 | 8 | Timer dt; // Instantiate a timer for clocking the Hz of the distance reads |
sventura3 | 0:efca88a80223 | 9 | int main() |
sventura3 | 0:efca88a80223 | 10 | { |
sventura3 | 0:efca88a80223 | 11 | |
sventura3 | 0:efca88a80223 | 12 | pc.baud(115200); // Set the baud rate for serial communication with the computer |
sventura3 | 0:efca88a80223 | 13 | Lidar.configure(); // Configure the Lidar |
sventura3 | 0:efca88a80223 | 14 | Lidar.beginContinuous();/* Set the lidar for continous reading |
sventura3 | 0:efca88a80223 | 15 | this mode makes the lidar pull pinMode low when ready to be read*/ |
sventura3 | 0:efca88a80223 | 16 | dt.start(); // Instantiate a timer for clocking the Hz of the distance reads |
sventura3 | 0:efca88a80223 | 17 | while(1){ |
sventura3 | 0:efca88a80223 | 18 | if(!pinMode) //Check if the lidar is pulling low |
sventura3 | 0:efca88a80223 | 19 | { |
sventura3 | 0:efca88a80223 | 20 | pc.printf("distance = %d cm frequency = %.2f Hz\n", Lidar.distanceContinuous(), 1/dt.read()); |
sventura3 | 0:efca88a80223 | 21 | /*Call the lidar distance function and and the timer read while printing out |
sventura3 | 0:efca88a80223 | 22 | both statements formatted to the computer through serial. */ |
sventura3 | 0:efca88a80223 | 23 | } |
sventura3 | 0:efca88a80223 | 24 | |
sventura3 | 0:efca88a80223 | 25 | } |
sventura3 | 0:efca88a80223 | 26 | } |