Line Robot - Basic lessons - Delay
If we want to pause program execution for a certain number of milliseconds, we will use function:
delayMs(numberOfMilliseconds)
For example, for a pause of 1 sec. (=1000 ms), run this program:
void RobotLine::loop() {
delayMs(1000);
}
Task: go forwards then backwards.
Moving robot backwards is the same as driving it forwards, except that the motors' speeds are negative.
void RobotLine::loop() {
go(-50, -50);
}
Now, write a program for moving Your robot 3 sec. forwards, then 3 sec. backwards, then stop.
Solution
void RobotLine::loop() {
if (setup()){
go(50, 50);
delayMs(3000);
go(-50, -50);
delayMs(3000);
stop();
}
}