mBot Keyboard Movement Code

This code will allow you to control your mBot using arrow keys on your computer.


 Step 1. Go to the EVENTS category.  Pull when space key pressed and when space key released into the programming area.  Switch space to up arrow.

 


Step 2. Switch to the Robots category.  Pull run forward at speed 100 underneath both up arrow key scripts.  Change the 100 on the 2nd script to 0.

This basically means, when you press up arrow, it will move forward at power level 100.  When you release the up arrow, it will put power to 0, or stop.

Now we will copy this code for down, left and right arrow keys.


Step 3. Right-click on the orange part of when up arrow key pressed.  Click duplicate and put the copy directly below the original.  Do this for when up arrow key released too.


Step 4. Change up arrow to down arrow on both of the clones.


Step 5. Change run forward to run backward on both scripts.


Step 6. Repeat steps 3 - 5 for right arrow, turn right and left arrow, turn left.

And now you're done!  Connect up the mBot and drive it around!