Line Robot - Basic lessons - Stop on line
The robot detects dark and bright surface using the line sensor. Arduino program can read one of its 9 (or less) transistors using command
line(transistorNumber). The result will be
true (if the surface is dark) or
false (if it is not). For example,
if (line(0))
print("Line");
else
print("White");
can be used to determine the surface. If the surface is dark, the first line (if...) will return "true" and that means that the command following "if" will be executed. That command will print "Line". On the other hand, when the surface is not dark, the "if..." will return "false" and that means that the command following "else" will be executed, printing "White". Try this program. The whole code is here:
void RobotLine::loop() {
if (line(0))
print("Line");
else
print("White");
}
Task: stop on line
Write a program that will be moving the robot straight ahead till it hits a dark surface below transistor 0.
Solution
void RobotLine::loop() {
if (line(0))
stop();
else
go(50, 50);
}