Fix ball detection logic by initializing ballLost to false and updating I2C address for seeker
This commit is contained in:
parent
8a5402570c
commit
62d206f792
1 changed files with 5 additions and 5 deletions
10
src/main.cpp
10
src/main.cpp
|
@ -35,7 +35,7 @@ OmniWheelMotors motors(MOTOR1_R_PWM, MOTOR1_L_PWM,
|
|||
int lastBallSensor = -1;
|
||||
int lastBallStrength = 255; // Start at max distance
|
||||
unsigned long lastBallDetectionTime = 0;
|
||||
bool ballLost = true;
|
||||
bool ballLost = false;
|
||||
|
||||
void setup() {
|
||||
// Initialize serial communication
|
||||
|
@ -158,10 +158,10 @@ void moveBasedOnSensor(int sensorNum, int strength) {
|
|||
}
|
||||
|
||||
void trackBall() {
|
||||
// Get IR ball direction from seeker (on I2C address 0x08)
|
||||
Wire.requestFrom(0x08, 2);
|
||||
|
||||
if (Wire.available() >= 2) {
|
||||
// Get IR ball direction from seeker (on I2C address 0x10 / 2)
|
||||
Wire.requestFrom(0x10 / 2, 2);
|
||||
|
||||
if (Wire.available()) {
|
||||
int sensorNum = Wire.read(); // Sensor number (1-12)
|
||||
int strength = Wire.read(); // Strength of the signal (0-255, 0 is closest)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue