Experiments for the Thames and Kosmos Computer Systems Engineering Kit
Program cp_dice.k

Rem Dice
Pdir = 63
L1: Random Portout = 1
Gosub L4: Input Check
Portout = 2
Gosub L4: Input Check
Portout = 3
Gosub L4: Input Check
Portout = 6
Gosub L4: Input Check
Portout = 7
Gosub L4: Input Check
Portout = 14
Gosub L4: Input Check
Goto L1: Random
L2: Dice down D = 1
PWM = 0
Beep
Delay = 255
L3: Dice falling A = D
B = 0
If A = B Goto L2: Dice down
L4: Input Check A = Uin
PWM = 0
Delay = 3
B = 6
If A < B Goto L3: Dice falling
D = 0
PWM = A
L5: SoundPortout = 16
Portout = 0
Delay = 30
Return
End

Download Program
Advanced Dice
This example demonstrates how easily the programs and experiments of the Thames and Kosmos microcontroller kit's user manual can be combined and extended.

The seven LEDs in the kit allow us to display the numbers between 1 and 6 the way it is done on the faces of a dice.
We only need 4 ports to trigger the LEDs! Since all Eyes of a dice except for the middle one occur in pairs we can connect these pairs to a single port each.
That leaves a spare port for some sound-atmosphere while the dice is rolling. The "Beep" indicates that the dice has come to a stop.
Instead of a push-button we use the motor with the wheel on it's top to roll the dice: Once we spin the wheel clockwise the dice starts rolling until we stop the wheel or it comes to a stop by itself. To avoid this from happening too soon we mix the dice-program (Number 32 in the manual) with the stop-and-go program (92). So the motor helps out a little to keep the wheel spinning. The volume of the sound can by adjusted with the knob, the push-button is an alternative for rolling the dice.
Microcontroller Dice
header