# 08m2 Dice game

#### mark Easterling

##### New Member
I am using the code below on a 08M2. The circuit runs well for about 10 seconds then goes wrong and flashes the LED's on/off very quickly and that all it does? Can anyone help please?

symbol z = w6

init: let dirs = %00010111
main:
label0:
Switch off 4
Switch off 2
Switch off 1
Switch off 0
pause 200
Switch on 4
Switch on 2
Switch on 1
Switch on 0
pause 200
random z
if Input3 is On then label0
if z > 55000 then label1
if z > 44000 then label2
if z > 33000 then label3
if z > 22000 then label4
if z > 11000 then label5
Switch on 4
Switch off 2
Switch off 1
Switch off 0
label6:
pause 2000
goto label0
label5:
Switch off 4
Switch on 2
Switch off 1
Switch off 0
goto label6
label4:
Switch on 4
Switch on 2
Switch off 1
Switch off 0
goto label6
label3:
Switch off 4
Switch on 2
Switch on 1
Switch off 0
goto label6
label2:
Switch on 4
Switch on 2
Switch on 1
Switch off 0
goto label6
label1:
Switch off 4
Switch on 2
Switch on 1
Switch on 0
goto label6

#### hex

##### Member
Works OK for me...

Try changing :
if Input3 is On then label0 ; keep fast-flashing all LEDs till input 3 low
for:
if Input3 is Off then label0 ; keep fast-flashing all LEDs till input 3 high

Like this:

C:
``````; random die roll program found on forum
; PICAXE 08m2 with button on input 3
; press button to take input 3 high and stop die from rolling

; LED pattern - on to light LED(s)
;
;    2   1
;    0 4 0
;    1   2

symbol z = w6

init:
let dirs = %00010111           ; 0, 1, 2, 4 outputs for LEDs

main:

Switch off 4                   ; all LEDs off for 200 ms
Switch off 2
Switch off 1
Switch off 0

pause 200

Switch on 4                    ; all LEDS on for 200 ms
Switch on 2
Switch on 1
Switch on 0

pause 200

random z                       ; get random number 0 to 65535

if Input3 is Off then main     ; keep fast-flashing all LEDs till input 3 high

if z > 55000 then pattern6     ; select pattern 1 to 6 randomly
if z > 44000 then pattern5
if z > 33000 then pattern4
if z > 22000 then pattern3
if z > 11000 then pattern2

Switch on 4                    ; pattern for "one"
Switch off 2
Switch off 1
Switch off 0

Displaydie:
pause 2000                     ; display LED pattern for 2 seconds
goto main

pattern2:
Switch off 4                   ; pattern for "two"
Switch on 2
Switch off 1
Switch off 0
goto Displaydie

pattern3:
Switch on 4
Switch on 2
Switch off 1
Switch off 0
goto Displaydie

pattern4:
Switch off 4
Switch on 2
Switch on 1
Switch off 0
goto Displaydie

pattern5:
Switch on 4
Switch on 2
Switch on 1
Switch off 0
goto Displaydie

pattern6:
Switch off 4
Switch on 2
Switch on 1
Switch on 0
goto Displaydie``````

Last edited:

#### mark Easterling

##### New Member
Thankyou so much, all working.
Mark