Soccer Robot C - Basic lessons - Exercises - Cross 2 lines
Task: the robot should cross 2 lines and stop after.
Put the robot in front of parallel 2 white stripes on a dark surface (but not on the first line). The robot must cross the both lines and stop at least 5 cm after the second.
Solution
void RobotSoccer::loop() {
static int lineFound = 0;
if (setup())
go(50, 0);
switch(lineFound){
case 0: // Before 1. line
if (!line(0, 0))
lineFound = 1;
break;
case 1: // On 1. line
if (line(0, 0))
lineFound = 2;
break;
case 2: // Before 2. line
if (!line(0, 0)){
delayMs(3000);
end();
}
break;
}
}