Code
The program for the jack-in-the-box used
auto thresholding to detect the ambient light and shadows cast upon
it. As soon as the sensor detected a shadow, part of the song
"Pop-Goes-the-Weasel" would be played in a loop. There was a
target count for the number of times a shadow was sensed and once it
reached it, the first part of the song would stop, the "Pop!" part of
the song would begin, and the jack would pop out of the box (a simple
motor would turn on for four seconds in one direction, then three
seconds in the reverse direction). Once it finished moving, there
would be a five second pause, the counter would reset itself to zero,
wait half a second, and then wait for the next shadow before beginning
the process all over again.
Because the sensor was
detecting all sorts of shadows and counting it
even when the crank was not covering it, the threshold was increased
from 20 to 40. The target count was also increased to 20.
A small piece of paper was placed around the sensor to decrease the
chances of other light and shadows interfering with the crank's
shadows.
In the exhibition room, the
lighting changed things. The target
count was decreased to 12, but this was still a bit too much. Six
or eight would have been a better number. Twelve was thought to
be a good number so that the song would at least be played once and
people could crank it as fast as they could and still hear the full
song. However, most participants cranked it slowly (I think in
fear of breaking it -- which did happen a couple of times by the way)
and thus made the wait for Jack to pop up even longer.
Mentioned in the Design section was how the
number of cranks would be random. I consider the number of cranks
random even though there is a target count because of how the sensor
reads other shadows besides the crank. The same number of cranks
would not always "pop" Jack, so it is semi-random.
The Song:
The song played was
"Pop-Goes-the-Weasel" and each note was chosen
through trial and error using the HandyBoard. Some of the notes
are not correct, but the general melody is there. Some pauses
would have been nice, but I was not able to get out the bugs in the
pauses, so just regular note XX was used instead (X standing for a
numeric digit). The song, as mentioned above, was split into
two. The "POP!" portion of the song was played when the motor
started and Jack got out of the box. Looping this part was
experimented, but it became annoying and was left to only play once.
Here are copies of the code
(including the song) in HandyLogo
and Text.
Next Page