Hello guys. I have a code as follow. I need some suggestion on how to improve it. My systems has 1 stepper, 1 servo motor, and 1 lidar sensor.
static unsigned long timer = 0;
unsigned long interval = 10; //1000/10 = 100 samples every second
if (millis() - timer > interval)
{
timer = millis();
myLidarLite.beginContinuous(false,0x13,0xff,0x62); //100Hz, infinite reading
distance = myLidarLite.distanceContinuous();...
When ever I try to get more samples by changing interval, the stepper is slow down (at 20 or more samples, at interval <50).
And in addition, the ** myLidarLite.beginContinuous(false,0x13,0xff,0x62);** seems to cause the Stepper to slow down also. Here is it part in the library .cpp file
void LIDARLite::beginContinuous(bool modePinLow, char interval, char numberOfReadings,char LidarLiteI2cAddress){
// Register 0x45 sets the time between measurements. 0xc8 corresponds to 10Hz
// while 0x13 corresponds to 100Hz. Minimum value is 0x02 for proper
// operation.
write(0x45,interval,LidarLiteI2cAddress);
// Set register 0x04 to 0x20 to look at "NON-default" value of velocity scale
// If you set bit 0 of 0x04 to "1" then the mode pin will be low when done
if(modePinLow){
write(0x04,0x21,LidarLiteI2cAddress);
}else{
write(0x04,0x20,LidarLiteI2cAddress);
}
// Set the number of readings, 0xfe = 254 readings, 0x01 = 1 reading and
// 0xff = continuous readings
write(0x11,numberOfReadings,LidarLiteI2cAddress);
// Initiate reading distance
write(0x00,0x04,LidarLiteI2cAddress);
}
Thank you for your time, any help is appreciated.
Tony.ino (2.61 KB)