Shop OBEX P1 Docs P2 Docs Learn Events
One armed bandit from random die — Parallax Forums

One armed bandit from random die

Statix_nsccStatix_nscc Posts: 4
edited 2010-11-23 10:42 in BASIC Stamp
Hello, i'm a student currently working on micro using the BASIC Stamp, I was wondering if anyone had any ideas on how to modify a random die program into a one armed bandit style setup.
Here is the code i'm currently using;
' {$STAMP BS2}
' {$PBASIC 2.5}
Segs VAR OUTL 'Segments on P0 - P7
SegsDirs VAR DIRL 'DIRS for segments

RollBtn PIN 15 'Roll button for die


RndVal VAR Word 'Random Number
swData VAR Byte 'workspace for BUTTON
dieVal VAR Nib 'new die value
spinPos VAR Nib 'spinner position
doSpin VAR Nib 'spinner update control

' .GFEDCBA
'
Digit0 DATA %00111111 ' Digit patterns
Digit1 DATA %00000110
Digit2 DATA %01011011
Digit3 DATA %01001111
Digit4 DATA %01100110
Digit5 DATA %01101101
Digit6 DATA %01111101
Digit7 DATA %00000111
Digit8 DATA %01111111
Digit9 DATA %01100111
' .GFEDCBA
'
Bug0 DATA %00000001 'Animated "bug" frames
Bug1 DATA %01000000
Bug2 DATA %00001000
Bug3 DATA %00000100
Bug4 DATA %00000010
Bug5 DATA %01000000
Bug6 DATA %00010000
Bug7 DATA %00100000

BugLen CON Bug7 - Bug0 +1 'calc animation length

Reset:
SegsDirs = %01111111 'make outputs for LEDs

Main:
DO
GOSUB Tumble_Die 'Shake the die
PAUSE 5 'Loop pad
'Check for button press
BUTTON Rollbtn, 0, 255, 5, swData, 1, Show_Die
LOOP
Show_Die:
READ (Digit0 + dieVal), Segs 'Transfer die to segments
PAUSE 1000 'Holds for viewing
GOTO Main 'Start again

Tumble_Die:
RANDOM rndVal 'Stir random value
dieVal = (rndVal // 9) + 1 'get die val, 1 - 6
doSpin = (doSpin + 1) // 10 'update spin timer
IF (doSpin = 0) THEN
spinPos = (spinPos + 1) // BugLen 'yes, point to next pos
READ (Bug0 + spinPos), Segs 'Output to segments
ENDIF
RETURN

Alot of the code was scavanged from the stampworks book, with a few changes.
I'd like to have it randomize between three to five, seven segment displays, i'm just looking for ideas on how to accomplish this, ideally segment 1 gets a random number, then segment 2 and so on until they are all activated.
I'm using the professional development board and the 5 displays it has on board.

Thanks for any help,

Cheers.
Sign In or Register to comment.