These functions can make mbot go forward, turn right, turn left, and go backward.
(moveSpeed is a valuable we set to control its speed.)
This is the function that allows our mbot to follow the line while moving around. Here, we set several variables , like lineFollowersensor and lineDirIndex. With these variables and a few if-else conditions. We get our mbot follow the path.
1. lineFollowSensor : varaible we used to get the information from the line follower sensor.
2.lineDirindex :variable we used to decide which way mbot will move.(4 modes :forward,backward,turnleft and turnRight.)
we set two wheels in different speed, so that the mbot can walk a circle until the line follower sensors detect black lines.
It will turn left, and make a circle by setting different speeds on the two wheels which we just mentioned before.
If mbot detect a obstacle, and its distance < 9 (also > 1 ), it will do the function obstacleAvoidance. Otherwise, mbot will do the function lineFollow to walk through the black lines.
Mbot will repeat this process when we press board button.