The Black Box

 

This is a top view of the interior of the black box. The bottom of the image is the side of the box on which the door is located. The platform can be seen at the bottom of the picture, just below the 40-tooth gear. The platform is in fact hanging from the gear. The motor is located at the upper righthand corner of the picture. The worm gear visible in the picture is connected directly to the motor, and when the motor turns the worm gear causes the 40-tooth gear to rotate slowly.

 

Also directly attached to the motor is a small wheel which is connected to several LEGO blocks (red and yellow on the upper left). A small piece of white paper is glued onto the bottom of the yellow LEGO block. As the motor turns, the white paper passes in front of an infrared sensor with each rotation. The cricket, which is attached to the sensor and the motor, keeps track of rotations via the IR sensor, and stops the motor after 20 rotations (i. e. a 180 degree rotation of the platform).

 

Thus, when the door is opened, the other side of the platform is revealed, and the object appears to have vanished.

 

 


 

 

The code:

global [rotations]

 

to rotate

loop [

waituntil [newir?]

a, on

setrotations 0

when [sensorA > 100] [setrotations rotations + 1]

waituntil [rotations = 20]

a, brake

setrotations 0

waituntil [newir?]

]

end

 

This code establishes a variable "rotations" to keep track of the number of times the motor has rotated. A piece of white paper glued to a LEGO piece passes in front of an infrared reflection sensor (sensorA) with each rotation of the motor, so each time the sensor, detects a nearby reflective surface (i. e. registers greater than 100) represents one rotation of the motor. Twenty rotations of the motor is equivalent to a 180 degree rotation of the platform, after which the motor brakes.

 

The "waituntil [newir?]" commands prevent the program from proceeding until it detects an IR signal from the wand. The "waituntil [newir?]" command at the beginning of the loop means that the loop will not begin until a message from the wand is detected. The "waituntil [newir?]" command at the end of the loop "absorbs" any infrared signals that might have been received while the program was running, so that the second cycle through the loop will only begin if an IR signal is detected AFTER the first cycle is complete.

Back to main Wand Page.