Version 2 of the program improved matters in the following ways.
First, four MyBlocks were defined and incoporated to prevent the program from becoming unwieldy, and allowing one common bit of code to be reused within the program.
Secondly, logic was developed so that the turntable could move directly from one ball release to the next, avoiding returning to the parked position in between.
The four MyBlocks were called ZeroTurntable, CloseGate, SayColour and setposition
ZeroTurntable switched on the turntable motor A in reverse until it returned to the parked position, when it pressed touch sensor 2, stopping the motor.
ClosedGate switched on the gate motor B in reverse until it caused touch sensor 1 to be pushed, and then stopped the motor.
SayColour dealt with the five way switch. It had a numeric input in the range 2 to 6, and spoke the associated colour value (2) green (3) yellow (4) red (5) or in the case of the default 6 which corresponds to white it said No followed by Object Detected, both sounds in the standard vocabulary.
setposition received a numeric integer input(which would be in the range -3 to + 4, and produced two outputs. A true/false direction output, true for forward with positive numbers input and false for reverse with negative numbers input. The second output equalled the size of the number multiplied by 360 to give a degrees duration output for the motor. This was always arranged to be a positive number.
The new program employs two variables. One called lastcolour holds the number of the last colour ball detected, and the second position holds the turntable position in number of revolutions from the parked position which is defined as 0.
The logic is explained on page 3. more...