Line Robot - Basic lessons - Exercises - Cross 2 lines
Task: the robot should cross 2 lines and stop after.
Put the robot in front of 2 lines (but not on the first line) that are parallel to its reflectance sensor and are parallel one to another. The robot must cross the both lines and stop at least 5 cm after the second.
Solution
void RobotLine::loop() {
static int lineFound = 0;
if (setup())
go(50, 50);
switch(lineFound){
case 0: // Before 1. line
if (line(0))
lineFound = 1;
break;
case 1: // On 1. line
if (!line(0))
lineFound = 2;
break;
case 2: // Before 2. line
if (line(0)){
delayMs(3000);
stop();
}
break;
}
}