/** * LIDARLite I2C Example * Author: Garmin * Modified by: Shawn Hymel (SparkFun Electronics) * Date: June 29, 2017 * * Read distance from LIDAR-Lite v3 over I2C * * See the Operation Manual for wiring diagrams and more information: * http://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf */ #include #include // Globals LIDARLite lidarLite; int cal_cnt = 0; int dt = 5; //time between samples (ms) float t = 0; //current time(ms) float tmax = 8*1000; //duration (ms) void setup() { Serial.begin(9600); // Initialize serial connection to display distance readings lidarLite.begin(0, true); // Set configuration to default and I2C to 400 kHz lidarLite.configure(0); // Change this number to try out alternate configurations } void loop() { int dist; while(t < tmax){ // At the beginning of every 100 readings, // take a measurement with receiver bias correction if ( cal_cnt == 0 ) { dist = lidarLite.distance(); // With bias correction } else { dist = lidarLite.distance(false); // Without bias correction } // Increment reading counter cal_cnt++; cal_cnt = cal_cnt % 100; t = millis(); // Display distance Serial.print(t); Serial.print(", "); Serial.println(dist); delay(dt); } while(1){} }