Line Robot - Basic lessons - Exercises - Boundary
Task: do not allow Your robot to cross a boundary.
Using a black stripe, make a square, or some other type of boundary, and program the robot so that it always moves inside the set limits (stripe).
Solution
void RobotLine::loop() {
if (setup())
go(60, 60);
if (line(4)){
go(100, -100);
delayMs(500);
go(60, 60);
}
}
Adjust the speeds and number of milliseconds. In the program, when transistor 4 detects black, the robot will rotate 180° in place and continue in the opposite direction, avoiding the boundary.