Soccer Robot C - 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 RobotSoccer::loop() {
delayMs(1000);
}
Task: go forwards then backwards.
Moving robot backwards is the same as driving it forwards, except that direction is opposite (180° instead of 0°).
void RobotSoccer::loop() {
go(50, 180);
}
Now, write a program for moving Your robot 3 sec. forwards, then 3 sec. backwards, then stop.
Solution
void RobotSoccer::loop() {
if (setup()){
go(50, 0);
delayMs(3000);
go(50, 180);
delayMs(3000);
stop();
}
}