Soccer Robot C - Basic lessons - Exercises - Function barrier
One more lesson for RCJ Soccer.
Task: modify function to be reliable.
barrier() is a predefined function which should signal if barrier is interrupted. It may look like this:
void RobotSoccer::barrier() {
return analogRead(35) < 300; // Adjust this value
}
Change the constant so that the function returns the most reliable result.
Solution
Modify "loop()":
void RobotSoccer::loop() {
print("%i\n\r", analogRead(35));
delayMs(100);
}
Start it and record maximum and minimum values. Of course, minimum will occur when the barrier is interrupted, maximum when not. Add the 2 values and divide by 2. That will be the value You should write instead of 300 in the original program.
From now on, You can use this function to detect a ball, instead of "analogRead()".