arduino LIGHTware SF20 library
#include <LW20.h> // Include the LW20 library
LW20 lw20(Serial1, 115200); // Instantiate the LW20 using the hardware Serial Port1 at 115200 baud
void setup()
{
// Start serial monitor port.
Serial.begin(115200); // Prepare the USB Terminal to use as a monitor
// Setup LW20.
lw20.init(); // Get the LW20 ready for commands
lw20.setLaserParams(LW20_MODE_388); // Set the LW20 update rate to 388 readings per second
lw20.setServoParams(1000, 2000, 10); // Configure the servo PWM from 1ms to 2ms with a resolution of 10us per degree
lw20.setScanParams(-30, 30, 8, 3.5); // Set the scanning field of view to ±30 degrees, stepping 8 times per result, compensating for 3.5 degrees of servo lag
lw20.setAlarmAParams(3.5, -15, 0); // Set up Alarm A at 3.5m in a segment from -15 degrees to straight ahead
lw20.setAlarmBParams(3.5, 0, 15); // Set up Alarm B at 3.5m in a segment from straight ahead to +15 degrees
lw20.startScan(); // Start an automatic scan using the above parameters
}
void loop()
{
// Check the alarm status every 100ms
bool a, b;
lw20.checkAlarmStatus(&a, &b); // Check the status of both alarms simultaneously
Serial.print("Alarm A:"); // Print out the alarm status on the USB Terminal
Serial.print(a);
Serial.print(" Alarm B:");
Serial.println(b);
delay(100);
}