Hello world for utilizing the Lidarlitev2 for distance measurements with the continuos reading setup
Dependencies: LidarLitev2 mbed
main.cpp
00001 #include "LidarLitev2.h" 00002 00003 LidarLitev2 Lidar(p28, p27);// Instantiate the LidarLitev2 with name Lidar and I2C pin (SDA, SCL) 00004 Serial pc(USBTX,USBRX); // Create a serial connection to pc through the mbed USB cable 00005 DigitalIn pinMode(p24); // This pin is to detect the mode out of the lidar in continous mode 00006 00007 00008 Timer dt; // Instantiate a timer for clocking the Hz of the distance reads 00009 int main() 00010 { 00011 00012 pc.baud(115200); // Set the baud rate for serial communication with the computer 00013 Lidar.configure(); // Configure the Lidar 00014 Lidar.beginContinuous();/* Set the lidar for continous reading 00015 this mode makes the lidar pull pinMode low when ready to be read*/ 00016 dt.start(); // Instantiate a timer for clocking the Hz of the distance reads 00017 while(1){ 00018 if(!pinMode) //Check if the lidar is pulling low 00019 { 00020 pc.printf("distance = %d cm frequency = %.2f Hz\n", Lidar.distanceContinuous(), 1/dt.read()); 00021 /*Call the lidar distance function and and the timer read while printing out 00022 both statements formatted to the computer through serial. */ 00023 } 00024 00025 } 00026 }
Generated on Thu Jul 21 2022 21:03:01 by 1.7.2