Fix ball detection logic by initializing ballLost to false and updating I2C address for seeker

This commit is contained in:
Andrea Moro 2025-02-28 14:58:48 +01:00
parent 8a5402570c
commit 62d206f792

View file

@ -35,7 +35,7 @@ OmniWheelMotors motors(MOTOR1_R_PWM, MOTOR1_L_PWM,
int lastBallSensor = -1; int lastBallSensor = -1;
int lastBallStrength = 255; // Start at max distance int lastBallStrength = 255; // Start at max distance
unsigned long lastBallDetectionTime = 0; unsigned long lastBallDetectionTime = 0;
bool ballLost = true; bool ballLost = false;
void setup() { void setup() {
// Initialize serial communication // Initialize serial communication
@ -158,10 +158,10 @@ void moveBasedOnSensor(int sensorNum, int strength) {
} }
void trackBall() { void trackBall() {
// Get IR ball direction from seeker (on I2C address 0x08) // Get IR ball direction from seeker (on I2C address 0x10 / 2)
Wire.requestFrom(0x08, 2); Wire.requestFrom(0x10 / 2, 2);
if (Wire.available() >= 2) { if (Wire.available()) {
int sensorNum = Wire.read(); // Sensor number (1-12) int sensorNum = Wire.read(); // Sensor number (1-12)
int strength = Wire.read(); // Strength of the signal (0-255, 0 is closest) int strength = Wire.read(); // Strength of the signal (0-255, 0 is closest)