Page 174 -
P. 174
243_masterpieces_03.qxd 4/18/03 7:02 PM Page 146
146 Masterpiece 3 • The LEGO Turning Machine
break;
}
Wait(100);
}
while (done != 1);
Float(OUT_A);
PlaySound(SOUND_UP);
}
After defining the machine’s general setup, the program starts using the state transition
table and the sensor reading to decide what to do (change state, move, write symbol),
until it has finished its job and the done variable is set to 1 (true).
Now that the program is finished, you can test the Turing machine you just created!
As you can see, the programming wasn’t too difficult. Remember:You can adjust the
robot’s behavior by modifying the three constants we’ve defined.And if you want to
change the state transition table, you just have to recode the switch…case statement of the
main task, and leave the rest as is.
Inventing…
Off and Float Modes
Note that before emitting a happy sound to let you know that everything’s over,
Motor A is set to Float. This is very useful if you want to manually move the tape
without having to switch the RCX off. If the motor is simply set to Off it will
remain connected and braked and trying to move the tape would be hard to do,
and would risk damaging some piece. If you put it in a Float state, it will be free
to move and we can easily modify the values of the cells and prepare the
machine for a new computation. Other methods include the use of a remote, or
the so-called console mode. For additional information on console mode, refer to
Chapter 2.
Operating the Turing Machine
Running the programmed Lego Turing Machine is very simple.You just have to put on
the tape the combination of symbols that you want to calculate with your program.The
cells are considered full (with a symbol) when the liftarm is in its upper position; that is,
opposite to the direction control mechanism, and vice versa.According to Turing’s defini-
tion, the machine starts operating with the leftmost cell of the tape placed in the read
head (as described in “The State Transition Table” section in the beginning of the
chapter.)
You may want to try the program we just described that adds two numbers.

