In order to steer mBot, first of all we must teach him to stop, otherwise as soon as he starts moving, we lose control. We simply tell him that, when we press the spacebar (for example) he must go forward at zero speed. Then we make sure that, when this happens, all the lights are off.

At this point, by always using the command when you press that button we tell him how to move, according to the key pressed: up arrow to go forward,down arrow to go back, right arrow to rotate to the right, left arrow to rotate to the left. We turn on the green lights when he goes forward, red when he goes back, and we make sure that only one light is on (for example, green) when he rotates right or left, while keeping the other light off. The speed can be set by selecting the desired value from the drop-down menu.

By adding this simple code, mBot willl stop when the arrow keys are released.

Leave a Reply

Your email address will not be published.