By integrating the Start Ranging and the Check on separate loops. The code can now run at full speed.
This allows us to reach 110Hz with 2 sensors, 150Hz with 3, 200 Hz with 4.
int detect_All() {
int range = 250;
int distanceAll = MAX_DISTANCE_SHORT_DETECTION;
for (int i = 0; i < NUMBER_OF_TOF_SENSORS; i++)
{
distanceSensor[i].setROI(16, 16, 198);
distanceSensor[i].startRanging(); //Write configuration bytes to initiate measurement
}
for (int i = 0; i < NUMBER_OF_TOF_SENSORS; i++)
{
while (!distanceSensor[i].checkForDataReady()) {
delay(1);
}
distanceAll = distanceSensor[i].getDistance(); //Get the result of the measurement from the sensor
if (distanceAll >= MAX_DISTANCE_SHORT_DETECTION) {
distanceAll = MAX_DISTANCE_SHORT_DETECTION;
}
distanceSensor[i].clearInterrupt();
distanceSensor[i].stopRanging();
if (distanceAll < range) {
return 1;
}
}
return 0;
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.