Drive a two-motor car from a dashboard joystick, with one function per direction.

This tutorial is part of the Nairda learning path. You can build it step by step inside the app, which checks every block you place before letting you move on.


The steps

  1. We add a While loop, which repeats forever.
  2. We declare motor1 on pins 2, 3 and 4.
  3. We declare motor2 on pins 5, 6 and 7.
  4. We create the functions forward and back.
  5. And the functions right, left and stop.
  6. In the forward canvas motor1 goes at speed 50.
  7. And motor2 goes at 50 too, so the car moves forward.
  8. In the back canvas motor1 goes at speed -50.
  9. And motor2 at -50 as well, so the car reverses.
  10. In the right canvas motor1 goes at speed 50.
  11. And motor2 goes at -50, the opposite way, so the car turns.
  12. In the left canvas motor1 goes at speed -50.
  13. And motor2 at 50, the opposite way, so it turns the other side.
  14. And in the stop canvas both go at speed 0.
  15. On the dashboard we draw a joystick.
  16. Pressing up calls forward.
  17. Pressing down calls back.
  18. Pressing right calls right.
  19. Pressing left calls left.
  20. Releasing up calls stop, so the car does not run away.
  21. Releasing down calls stop too.
  22. Releasing right calls stop.
  23. And releasing left calls stop as well.

When you finish, the app takes you straight to the next tutorial in the path.

Build it in Nairda