Download Program:stopwatch-nxt-robot.rbt
This Page as PDF:stopwatch-nxt-robot.pdf

Stopwatch NXT Robot

Stefan Bracher

The Lego Mindstorms NXT Robot can be transformed into a stopwatch using a pushbutton. The presented NXT-program starts counting the time in milliseconds from the moment the pushbutton is pressed and stops when the button is released. The result is then shown on the display.

Stopwatch NXT Robot

NXT G-Code

NXT-G Code

The program consists of two loops, an outer and an inner loop. The outer loop makes the program run forever. This way, the stopwatch can be used to measure several time intervals in a row without having to restart the program.

The first command is a “Wait For Button Pressed” command. The program waits until the pushbutton is pressed down. As soon as this happens, the timer is reset to zero and the inner loop starts counting.

In the inner loop, the output of the timer (the number of milliseconds) is sent to the display of the robot. Because the display can only show “Texts” but no “Numbers”, the number has to be converted to text first. This inner loop repeats itself until the button is released.

Once the inner loop stops repeating itself (The pushbutton was released), a beep alerts the user that the measured value can now be read from the display. The stopwatch is now ready to run again.