Could someone point me in the right direction please?
Mike W
Posts: 105
Could someone point me in the right direction please? I am using the Professional Developement Board and my intentions were to write a program to simulate a slot machine with the 7 segment displays. I wanted to scroll three random digits and light the appropriate digit one after the other, after a small delay each. I have wired the 7 segment displays as in StampWorks v2.0· Experiment #10 page 67
Right now i am just trying to get 3 random digits to display.
Mike W
' {$STAMP BS2e}
' {$PBASIC 2.5}
'
' ==============================================================================
'
'
[noparse][[/noparse] Program Description ]
'
'· Scroll three random numbered digits stoping one at a time like a slot machine
'
'
[noparse][[/noparse] I/O Definitions ]
Segs··········· VAR···· OUTL··················· ' segments
Digs············ VAR···· OUTC··················· ' digit select
'
[noparse][[/noparse] Constants ]
Blank·········· CON···· %00000000·············· ' all segments off
'
[noparse][[/noparse] Variables ]
rndVal········· VAR···· Word··················· ' Random number
cnt············· VAR···· Word··················· ' seconds
number·········VAR···· Word··················· ' formatted number
theDig········· VAR···· Nib···················· ' current display digit
'
[noparse][[/noparse] EEPROM Data ]
'············ ················ .GFEDCBA
'·················· ············
·············· ' digit patterns
Digit0········· DATA··· %00111111·············· ' 0
Digit1········· DATA··· %00000110·············· ' 1
Digit2········· DATA··· %01011011·············· ' 2
Digit3········· DATA··· %01001111·············· ' 3
Digit4········· DATA··· %01100110·············· ' 4
Digit5········· DATA··· %01101101·············· ' 5
Digit6········· DATA··· %01111101·············· ' 6
Digit7········· DATA··· %00000111·············· ' 7
Digit8········· DATA··· %01111111·············· ' 8
Digit9········· DATA··· %01101111·············· ' 9
DigSel········· DATA··· %1101·················· ' digit 1 active
················ ·DATA··· %1011·················· ' digit 2 active
················· DATA··· %0111·················· ' digit 3 active
'
[noparse][[/noparse] Initialization ]
Reset:
· Digs = %1111································· ' all off
· DIRS = $0FFF································· ' make segs & digs outputs
· cnt = 0
'
[noparse][[/noparse] Program Code ]
Main:
··· GOSUB Spin_wheel_1························· ' updata current number
··· GOSUB Spin_wheel_2
··· GOSUB Spin_wheel_3
··· PAUSE 100
·· END
· 'GOTO Main
'
[noparse][[/noparse] Subroutines ]
Show_Counter:
· Segs = Blank································· ' clear display
· READ (DigSel + theDig), Digs················· ' select digit
· READ (Digit0 + (number // 10)), Segs········· ' move digit pattern in segs
· PAUSE 10
· RETURN
Spin_wheel_1:
· RANDOM rndVal································ ' stir random value
· cnt = (rndVal // 10)
·theDig = 2···································· ' digit pointer
· number = number + (cnt // 100)··············· ' get 100s
· GOSUB Show_Counter
RETURN
Spin_wheel_2:
· RANDOM rndVal································ ' stir random value
· cnt = (rndVal // 10)
·theDig = 1···································· ' digit pointer
· number = number + (cnt // 10)················ ' get· 10s
· GOSUB Show_counter
RETURN
Spin_wheel_3:
· RANDOM rndVal································ ' stir random value
· cnt = (rndVal // 10)
·theDig = 0···································· ' a digit pointer
· number = number + cnt························ ' get· 1s
· GOSUB Show_counter
RETURN··
Right now i am just trying to get 3 random digits to display.
Mike W
' {$STAMP BS2e}
' {$PBASIC 2.5}
'
' ==============================================================================
'
'
[noparse][[/noparse] Program Description ]
'
'· Scroll three random numbered digits stoping one at a time like a slot machine
'
'
[noparse][[/noparse] I/O Definitions ]
Segs··········· VAR···· OUTL··················· ' segments
Digs············ VAR···· OUTC··················· ' digit select
'
[noparse][[/noparse] Constants ]
Blank·········· CON···· %00000000·············· ' all segments off
'
[noparse][[/noparse] Variables ]
rndVal········· VAR···· Word··················· ' Random number
cnt············· VAR···· Word··················· ' seconds
number·········VAR···· Word··················· ' formatted number
theDig········· VAR···· Nib···················· ' current display digit
'
[noparse][[/noparse] EEPROM Data ]
'············ ················ .GFEDCBA
'·················· ············
·············· ' digit patterns
Digit0········· DATA··· %00111111·············· ' 0
Digit1········· DATA··· %00000110·············· ' 1
Digit2········· DATA··· %01011011·············· ' 2
Digit3········· DATA··· %01001111·············· ' 3
Digit4········· DATA··· %01100110·············· ' 4
Digit5········· DATA··· %01101101·············· ' 5
Digit6········· DATA··· %01111101·············· ' 6
Digit7········· DATA··· %00000111·············· ' 7
Digit8········· DATA··· %01111111·············· ' 8
Digit9········· DATA··· %01101111·············· ' 9
DigSel········· DATA··· %1101·················· ' digit 1 active
················ ·DATA··· %1011·················· ' digit 2 active
················· DATA··· %0111·················· ' digit 3 active
'
[noparse][[/noparse] Initialization ]
Reset:
· Digs = %1111································· ' all off
· DIRS = $0FFF································· ' make segs & digs outputs
· cnt = 0
'
[noparse][[/noparse] Program Code ]
Main:
··· GOSUB Spin_wheel_1························· ' updata current number
··· GOSUB Spin_wheel_2
··· GOSUB Spin_wheel_3
··· PAUSE 100
·· END
· 'GOTO Main
'
[noparse][[/noparse] Subroutines ]
Show_Counter:
· Segs = Blank································· ' clear display
· READ (DigSel + theDig), Digs················· ' select digit
· READ (Digit0 + (number // 10)), Segs········· ' move digit pattern in segs
· PAUSE 10
· RETURN
Spin_wheel_1:
· RANDOM rndVal································ ' stir random value
· cnt = (rndVal // 10)
·theDig = 2···································· ' digit pointer
· number = number + (cnt // 100)··············· ' get 100s
· GOSUB Show_Counter
RETURN
Spin_wheel_2:
· RANDOM rndVal································ ' stir random value
· cnt = (rndVal // 10)
·theDig = 1···································· ' digit pointer
· number = number + (cnt // 10)················ ' get· 10s
· GOSUB Show_counter
RETURN
Spin_wheel_3:
· RANDOM rndVal································ ' stir random value
· cnt = (rndVal // 10)
·theDig = 0···································· ' a digit pointer
· number = number + cnt························ ' get· 1s
· GOSUB Show_counter
RETURN··
Comments
Main:
····· rndVal=1
····· DO WHILE IN15 = 0
····· rndVal = rndVal +1
····· IF rndVal >65534 THEN
····· rndVal=1
····· ENDIF
····· LOOP
··· GOSUB Spin_wheel_1
··· PAUSE 500
··· GOSUB Spin_wheel_2
··· PAUSE 500
··· GOSUB Spin_wheel_3
·GOTO Main
Jeff T.
thanks for the reply
although the same numbers do keep comming up I was having more trouble multiplexing 3 digits
a button will be incorporated to start the roll but I was thinking it would stop it's self.
say push button and digits 1 - 3 scroll rapidly random numbers between 0 and 9. At a given interval digit one would stop and display a number, digits 2 and 3 will still continue to scroll then digit two would stop and number 1 and 2 would be displayed leaving digit 3 scroll until it finally stops.
mike w
idx VAR Nib
··· FOR idx = 1 TO 10
··· GOSUB Spin_wheel_1
··· GOSUB Spin_wheel_2
··· GOSUB Spin_wheel_3
··· PAUSE 200
··· NEXT
··· FOR idx = 1 TO 10
··· GOSUB Spin_wheel_2
··· GOSUB Spin_wheel_3
··· PAUSE 200
··· NEXT
··· FOR idx = 1 TO 10
··· GOSUB Spin_wheel_3
··· PAUSE 200
··· NEXT
lastly looking at your code I think you could possibly get rid of the "number" variable all together so each Spin_wheel would be
Spin_wheel_1:
· RANDOM rndVal
· cnt = (rndVal // 10)
· theDig = 2
· GOSUB Show_Counter
RETURN
then adjust Show_Counter like this
Show_Counter:
· Segs = Blank
· READ (DigSel + theDig), Digs
· READ (Digit0 + cnt), Segs
· RETURN
Jeff T.
At first I did not uderstand your thought about putting the push button in now, but it does make better sense. I will work with your suggestions and advise and see if I can get it together.
Thanks again,
Mike
·
On the first run things go as expected, push the button and the numbers scroll stopping one at a time and displaying three random digits.
·
On the next push the numbers scroll but they always stop on 046 unless I do a reset
·
I have tried clearing the wheel variables with no success
I have included the new code below
·
Any suggestions
·
Mike W
'
[noparse][[/noparse] Program Description ]
'
'· Scroll three random numbered digits stoping one at a time like a slot machine
'
'
[noparse][[/noparse] I/O Definitions ]
Segs··········· VAR···· OUTL··················· ' segments
Digs··········· VAR···· OUTC··················· ' digit select
'
[noparse][[/noparse] Constants ]
Blank·········· CON···· %00000000·············· ' all segments off
'
[noparse][[/noparse] Variables ]
idx············ VAR···· Nib···················· ' Counter
theDig········· VAR···· Nib···················· ' current display digit
wheel_1_Dig···· VAR···· Nib···················· '· hold
wheel_2_Dig···· VAR···· Nib···················· '· digit
wheel_3_Dig···· VAR···· Nib···················· '· value
wheel_1_Seg···· VAR···· Byte··················· '· hold
wheel_2_Seg···· VAR···· Byte··················· '· segment
wheel_3_Seg···· VAR···· Byte··················· '· value
rndVal········· VAR···· Word··················· ' Random number
cnt············ VAR···· Word··················· ' count
'
[noparse][[/noparse] EEPROM Data ]
'······················· .GFEDCBA
'·······················
·············· ' digit patterns
Digit0········· DATA··· %00111111·············· ' 0
Digit1········· DATA··· %00000110·············· ' 1
Digit2········· DATA··· %01011011·············· ' 2
Digit3········· DATA··· %01001111·············· ' 3
Digit4········· DATA··· %01100110·············· ' 4
Digit5········· DATA··· %01101101·············· ' 5
Digit6········· DATA··· %01111101·············· ' 6
Digit7········· DATA··· %00000111·············· ' 7
Digit8········· DATA··· %01111111·············· ' 8
Digit9········· DATA··· %01101111·············· ' 9
DigSel········· DATA··· %0110·················· ' digit 1 active
··············· DATA··· %0101·················· ' digit 2 active
··············· DATA··· %0011·················· ' digit 3 active
'
[noparse][[/noparse] Initialization ]
Reset:
· INPUT 15
· Digs = %1111································· ' all off
· DIRS = $0FFF································· ' make segs & digs outputs
'
[noparse][[/noparse] Program Code ]
Main:
· rndVal=1
··· DO WHILE IN15 = 1
···· rndVal = rndVal +1
····· IF rndVal >65534 THEN
····· rndVal=1
····· ENDIF
··· LOOP
·FOR idx = 1 TO 10
··· GOSUB Spin_Wheel_1
··· GOSUB Spin_Wheel_2
··· GOSUB Spin_Wheel_3
·· PAUSE 10
· NEXT
·FOR idx = 1 TO 10
··· GOSUB Spin_Wheel_2
··· GOSUB Spin_Wheel_3
·· PAUSE 10
· NEXT
·FOR idx = 1 TO 10
··· GOSUB Spin_Wheel_3
·· PAUSE 10
· NEXT
·DO
· GOSUB show_display
·LOOP UNTIL IN15 = 0
· GOTO MAIN
'
[noparse][[/noparse] Subroutines ]
Show_Display:
·· Digs = wheel_1_dig
·· Segs = wheel_1_seg
· PAUSE 2
·· Digs = wheel_2_dig
·· Segs = wheel_2_seg
· PAUSE 2
·· Digs = wheel_3_dig
·· Segs = wheel_3_seg
· PAUSE 2
·RETURN
Get_Display:
· Segs = Blank
· READ (DigSel + theDig), Digs
· READ (Digit0 + cnt), Segs
· RETURN
Spin_Wheel_1:
·· RANDOM rndVal······························· ' stir random value
·· cnt = (rndVal // 10)
· theDig = 2··································· ' digit pointer
·GOSUB Get_Display
·· wheel_1_Dig = Digs·························· ' save digit and segment
·· wheel_1_Seg = Segs·························· ' values
·GOSUB Show_Display
·RETURN
Spin_Wheel_2:
·· RANDOM rndVal······························· ' stir random value
·· cnt = (rndVal // 10)
· theDig = 1··································· ' digit pointer
·GOSUB Get_Display
·· wheel_2_Dig = Digs
·· wheel_2_Seg = Segs
·GOSUB Show_Display
·RETURN
Spin_Wheel_3:
·· RANDOM rndVal······························· ' stir random value
·· cnt = (rndVal // 10)
· theDig = 0··································· ' a digit pointer
·GOSUB Get_Display
·· wheel_3_Dig = Digs
·· wheel_3_Seg = Segs
·GOSUB Show_Display
·RETURN
' =================================[noparse][[/noparse] EOF ]==============================
Jeff T.
I took the second Do Loop out like you seggested and replaced it with
FOR idx = 1 TO 250
· GOSUB show_display
· NEXT
·GOTO MAIN
This shows the display for a couple of seconds and then starts again.
The second Do Loop was defiantly causing the problem. now to add a couple of bells and whistles
Mike W
Thanks to Jeff for his help.
The program scrolls three digits randomly stopping them one at a time and displaying the digits.
If all three digits match a tone is sounded