Hello world for utilizing the Lidarlitev2 for distance measurements with the continuos reading setup
Dependencies: LidarLitev2 mbed
Diff: main.cpp
- Revision:
- 0:efca88a80223
diff -r 000000000000 -r efca88a80223 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Oct 22 22:32:02 2015 +0000
@@ -0,0 +1,26 @@
+#include "LidarLitev2.h"
+
+LidarLitev2 Lidar(p28, p27);// Instantiate the LidarLitev2 with name Lidar and I2C pin (SDA, SCL)
+Serial pc(USBTX,USBRX); // Create a serial connection to pc through the mbed USB cable
+DigitalIn pinMode(p24); // This pin is to detect the mode out of the lidar in continous mode
+
+
+Timer dt; // Instantiate a timer for clocking the Hz of the distance reads
+int main()
+{
+
+ pc.baud(115200); // Set the baud rate for serial communication with the computer
+ Lidar.configure(); // Configure the Lidar
+ Lidar.beginContinuous();/* Set the lidar for continous reading
+ this mode makes the lidar pull pinMode low when ready to be read*/
+ dt.start(); // Instantiate a timer for clocking the Hz of the distance reads
+ while(1){
+ if(!pinMode) //Check if the lidar is pulling low
+ {
+ pc.printf("distance = %d cm frequency = %.2f Hz\n", Lidar.distanceContinuous(), 1/dt.read());
+ /*Call the lidar distance function and and the timer read while printing out
+ both statements formatted to the computer through serial. */
+ }
+
+ }
+}
\ No newline at end of file