Clifford
goes to Treasure Island
|
global [waittime direction] | Defines two global variables |
to search
end |
The main procedure: searching for treasure It sets the variable “waittime” to be a random time between 2000 and 5000 millisec. (2 - 5 seconds), then calls the procedure “go-straight”. It runs through these if statements until the program is stopped. If one of the conditions is true, it calls the procedure in brackets. |
to go-straightend |
To go straight, the brush must be in the up position. The left and right motors are then turned on, to go forward (“thisway”). |
to sees-left-magnet?end |
Switch 7 is a magnet sensor. The output will be 1 if a magnet is near and 0 if there is no magnet. Essentially, 1 is true and 0 is false. |
to handle-left-magnetend |
If there is a magnet, the brush sweeps to reveal it. The LED screen on the handy board reads “treasure!”, and the wheels are stopped. The handy board beeps. Both wheels then reverse (“on thatway”) for 0.5 seconds. They then stop, and the procedure sweep is called. Clifford then backs up so that the observer can take out the treasure. After waiting ten seconds, the program returns to the main procedure, search. |
to sweepend |
This is the sweep procedure, used to reveal the treasure. The motor controlling the brush is turned on, and the brush sweeps three times. There is a touch sensor that is pushed down when the brush is in the upwards position. Once the brush has been not pressed and then pressed three times, the brush stops and the handy board returns to the handle-right-magnet or handle-left-magnet procedure. |
to bumper?end |
When the bumper is pushed in by the wall, a touch sensor connected to switch port 10 is depressed, making the output of the switch be 1 rather than 0. |
to handle-bumperend |
When the bumper is hit, Clifford backs up. Clifford beeps once to indicate that his bumper was hit. Then he resets the built-in timer. He then turns on the left and right motors in the reverse directions (“thisway” indicates forward, “thatway” indicates reverse). The program then runs through the infinite loop, checking to see if the if statements are true or not. He is still checking for treasure. Once he has backed up for 10 seconds, the program returns to the search procedure. |
to time-to-turn?end |
The variable waittime was set earlier to a number between 2000 and 5000 milliseconds. If the timer reads higher than that number, then it is time to turn. |
to random-turnend |
If it is time to turn, this is the procedure that is called. The variable direction is set to be a random number between 0 and 5. If the number is 0, 1, 2, or 3, Clifford goes straight. If it is 4, he turns left. If it is 5, he turns right. The variable waittime is then re-chosen and the timer is reset before Clifford returns to the main search program. |
to stop-motionend |
|
to turn-left
end |
To turn, one side turns in the forward direction and one side moves in the backward direction. |
to turn-rightend |
|
to sees-right-magnet?end |
|
to handle-right-magnetend |
|
to right-motorend |
Each of the motor ports is assigned a letter, a through d. The right motor is plugged into motor port b. |
to left-motorend |
|
to brushend |
|
to stop-allend |
This stops all of the motors. |