LEGO NXT button control

You can control your robot easily with buttons on the stage. The following instruction shows you how to program it. Each button represents one direction. Once a button is tapped, both engines stops and only the needed engine or enginess for the desired direction is driven again. You save the direction in the variable dir (= direction) to control the engines. Look inside the program.
Plug the engines as follows: A: Engine for the arm of the robot / B: Engine for the right wheel. / C: Engine for the left wheel.


1) This image shows the needed objects. For each direction one object can be created.

2) Here the needed bricks of the object "forward" are displayed. When the button is tapped, the direction is set through the variable dir. As long as this value of the variable is not changed by another object respectively by tapping on an other object, the robot moves straight ahead.