PHASE 10 level decider

newplumber

Senior Member
Hi
I wanted to make a 10 digit display so I could random do levels on the card game Phase 10
Thanks to Hippy which gave me the random code/idea and Westaust55 for making sample codes for the max7219
What this project does is just basically gives a random order of level as you play the game

first part of code
Code:
#PICAXE 20M2  '/// PHASE TEN GAME NUMBER DECIDER
#NO_DATA      '/// uses two max7219 chips and one picaxe 20m2 
SETFREQ M32   '/// shows random levels in order on a 10 digit display 

; SYMBOL Definitions
SYMBOL DIn_7219	= PINB.0  ' 20m2  pin # 18
SYMBOL Load_7219	= B.2     ' 20m2  pin # 16
SYMBOL Clk_7219	= B.1     ' 20m2  pin # 17

; MAX7219 Registers - 
SYMBOL No_Op	= 0
SYMBOL Digit0	= 1
SYMBOL Digit1	= 2
SYMBOL Digit2	= 3
SYMBOL Digit3	= 4 ; for more digits, dig4 thru dig7 = 5 to 8 respectively
SYMBOL Digit4	= 5
SYMBOL Digit5	= 6
SYMBOL Digit6	= 7
SYMBOL Digit7	= 8 
SYMBOL Digit8	= 9
SYMBOL Digit9	= 10
SYMBOL Decode	= 9
SYMBOL Intens	= 10
SYMBOL ScanLim	= 11
SYMBOL ShutDwn	= 12
SYMBOL DigTest	= 15

SYMBOL Set_Off	= 0
SYMBOL Set_On 	= 1
SYMBOL No_Digits	= 7 	; Scan limit for digits 0 to 3 = 4
SYMBOL Dec_Digits = 0	; decode digits 0 to 3 according to "code B"
SYMBOL Init_Inten = 12	; 0 (=1/32 PWM on time) to 15 (=31/32 PWM on time)
SYMBOL DigBlank	= 15	; "Code B" value to black a digit
SYMBOL DecimPnt	= 128 ; Add this value to a digit value/code when we want the demical point illuminated

; Define variables
SYMBOL Data_7219	   = b0
SYMBOL Register	   = b1
Symbol reserveW0     = w1 ; b2:b3
Symbol randomNumber  = w2 ; b4:b5
Symbol numberOfCards = b6
Symbol choosenCard   = b7
Symbol level         = b8
Symbol card1         = b9
Symbol card2         = b10
Symbol card3         = b11
Symbol card4         = b12
Symbol card5         = b13
Symbol card6         = b14
Symbol card7         = b15
Symbol card8         = b16
Symbol card9         = b17
Symbol card10        = b18

Symbol PTIME         = W10 'b20:b21  pause time for clear display to scroll 
Symbol S_Switch      = B22 ' value of switch on pinC.1 or PinC.0 
Symbol B_Switch      = b23 ' value if both switches are pressed at the same time 

;===============================================
; Initialise the PICAXE Pins for communication with the MAX7219
;===============================================
Init:
	DIRSB = %00000111
	DIRSC = %00000000
	LOW Load_7219
	LOW Clk_7219
	DIn_7219 = 0
	
;===============================================
; Main Program loop
;===============================================	
GOSUB Initialise7219 'program both max7219 displays 

START:
gosub all_ready 	
DO
    B_Switch = 0 
    If numberOfCards = 0 and S_Switch = 1 Then gosub ONE_AT_TIME 'display 10 digits per switch pushed 
     If numberOfCards = 0 and S_Switch = 0 Then	    
       bptr = 30 
     ' SerTxd( CR, LF, "New:" )
      Gosub StartWithTenCards
    EndIf
    Gosub ChooseRandom
    Gosub ReadCard  
    'SerTxd( " ", #level )
    @bptrinc = level
    IF pinc.1 = 1 And pinc.0 = 0 or pinc.1 = 0 And pinc.0 = 1 then :S_Switch = 1 :endif 
    Gosub RemoveChosenCard
LOOP
StartWithTenCards:
  numberOfCards = 10
  card1  = 1
  card2  = 2
  card3  = 3
  card4  = 4
  card5  = 5
  card6  = 6
  card7  = 7
  card8  = 8
  card9  = 9
  card10 = 10
  Return

ChooseRandom:
  For b0 = 0 To 10
    Random randomNumber
    IF pinc.1 = 1 And pinc.0 = 0 or pinc.1 = 0 And pinc.0 = 1 then :S_Switch = 1 :endif
  Next
  choosenCard = randomNumber ** numberOfCards + 1
  Return

ReadCard:
  Select Case choosenCard
    Case 1  : level = card1
    Case 2  : level = card2
    Case 3  : level = card3
    Case 4  : level = card4
    Case 5  : level = card5
    Case 6  : level = card6
    Case 7  : level = card7
    Case 8  : level = card8
    Case 9  : level = card9
    Case 10 : level = card10
  End Select
Return

RemoveChosenCard:
  If choosenCard  = 1 Then : card1 = card2  : End If
  If choosenCard <= 2 Then : card2 = card3  : End If
  If choosenCard <= 3 Then : card3 = card4  : End If
  If choosenCard <= 4 Then : card4 = card5  : End If
  If choosenCard <= 5 Then : card5 = card6  : End If
  If choosenCard <= 6 Then : card6 = card7  : End If
  If choosenCard <= 7 Then : card7 = card8  : End If
  If choosenCard <= 8 Then : card8 = card9  : End If
  If choosenCard <= 9 Then : card9 = card10 : End If
  numberOfCards = numberOfCards - 1
Return	  	  
ALL_READY:' shows display waiting for switch input
Card10 = $7E	:card9   = $00 
card8  = $30	:card7   = $00  
card6  = $4E	:card5   = $00 
card4  = $00      :card3   = $77	  
card2  = $4E	:card1   = $4F  
gosub SetDigitDisplay_to_scroll	  
RETURN
ALL_OFF:' shows display waiting for switch input
Card10 = $00	:card9   = $00 
card8  = $00	:card7   = $00  
card6  = $00	:card5   = $00 
card4  = $00      :card3   = $00	  
card2  = $00	:card1   = $00 
gosub SetDigitDisplay_to_scroll	  
RETURN

ONE_AT_TIME: ' makes each digit display one at time per switch is pressed	
gosub ALL_OFF : pause 10000
Peek 30,card1:Peek 31,card2:Peek 32,card3:Peek 33,card4:Peek 34,card5
Peek 35,card6:Peek 36,card7:Peek 37,card8:Peek 38,card9:Peek 39,card10

			LOOKUP card1,  ($7E, $30, $6D, $79, $33, $5B, $5F, $70, $7F, $7B, $7E), card1
 			LOOKUP card2,  ($7E, $30, $6D, $79, $33, $5B, $5F, $70, $7F, $7B, $7E), card2
			LOOKUP card3,  ($7E, $30, $6D, $79, $33, $5B, $5F, $70, $7F, $7B, $7E), card3  
			LOOKUP card4,  ($7E, $30, $6D, $79, $33, $5B, $5F, $70, $7F, $7B, $7E), card4	  
			LOOKUP card5,  ($7E, $30, $6D, $79, $33, $5B, $5F, $70, $7F, $7B, $7E), card5	  
			LOOKUP card6,  ($7E, $30, $6D, $79, $33, $5B, $5F, $70, $7F, $7B, $7E), card6	  
			LOOKUP card7,  ($7E, $30, $6D, $79, $33, $5B, $5F, $70, $7F, $7B, $7E), card7	  
			LOOKUP card8,  ($7E, $30, $6D, $79, $33, $5B, $5F, $70, $7F, $7B, $7E), card8	  
			LOOKUP card9,  ($7E, $30, $6D, $79, $33, $5B, $5F, $70, $7F, $7B, $7E), card9
			LOOKUP card10, ($7E, $30, $6D, $79, $33, $5B, $5F, $70, $7F, $7B, $7E), card10
			
			'$7E, $30, $6D, $79, $33, $5B, $5F, $70, $7F, $7B, $77, $1F, $4E, $3D, $4F, $47
			'  0    1    2    3    4    5    6    7    8    9    A    b    c    d    E    F

' second max7219 only 2 digits used  ---------------------------------------------	
	Register = Digit1	 : Data_7219 = card10 : GOSUB ShiftTo7219  
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :GOSUB CHECK_SWITCH		
	Register = Digit0	 : Data_7219 = card9 : GOSUB ShiftTo7219 
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :GOSUB CHECK_SWITCH	
	
'first max7219 all 8 digits used  ------------------------------------------------	
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit7	 : Data_7219 = card8 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :GOSUB CHECK_SWITCH		
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit6	 : Data_7219 = card7 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :GOSUB CHECK_SWITCH	     
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit5	 : Data_7219 = card6 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :GOSUB CHECK_SWITCH     
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit4	 : Data_7219 = card5 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :GOSUB CHECK_SWITCH	     
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit3	 : Data_7219 = card4 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :GOSUB CHECK_SWITCH	     
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit2	 : Data_7219 = card3 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :GOSUB CHECK_SWITCH	    
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit1	 : Data_7219 = card2 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :GOSUB CHECK_SWITCH	    
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit0	 : Data_7219 = card1 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :GOSUB CHECK_SWITCH
    Pause 4000  ' delay so switch can release 
RETURN
SetDigitDisplay_TO_SCROLL: ' scrolls display on or off 
ptime = 1000
' second max7219  ---------------------------------------------	
	Register = Digit1	 : Data_7219 = card10 : GOSUB ShiftTo7219  
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219    : PULSOUT Load_7219, 1 :pause Ptime 		
	Register = Digit0	 : Data_7219 = card9 : GOSUB ShiftTo7219 
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219    : PULSOUT Load_7219, 1 :pause Ptime	
	
'first max7219  ------------------------------------------------	
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit7	 : Data_7219 = card8 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :pause Ptime		
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit6	 : Data_7219 = card7 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :pause Ptime	     
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit5	 : Data_7219 = card6 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :pause Ptime    
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit4	 : Data_7219 = card5 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :pause Ptime	     
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit3	 : Data_7219 = card4 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :pause Ptime	     
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit2	 : Data_7219 = card3 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :pause Ptime	    
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit1	 : Data_7219 = card2 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :pause Ptime	    
	Register = $00	 : Data_7219 = $00 : GOSUB ShiftTo7219  
	Register = Digit0	 : Data_7219 = card1 : GOSUB ShiftTo7219  : PULSOUT Load_7219, 1 :pause Ptime	    
RETURN
 

Attachments

newplumber

Senior Member
Second part of the code
Code:
CHECK_SWITCH: ' checks for switch on/off, to display next digit or incase both switches 
'are pressed at the same time then it will display all 10 digits 
S_Switch = 1
If B_Switch = 1 then goto skip_loop
Pause 4000 ' delay so switch can release
DO 
IF pinc.1 = 1 And pinc.0 = 0 then :S_Switch = 0
	Elseif pinc.0 = 1 And pinc.1 = 0 then
S_Switch = 0 :endif
IF pinc.1 = 1 And pinc.0 = 1 then  'if both switches are pressed then display all numbers
B_Switch = 1 :S_Switch = 0 :goto skip_loop:endif	
	
LOOP until S_Switch = 0 ' wait for pinc.1 or pinc.0 to be pressed 
SKIP_LOOP:
RETURN
ShiftTo7219:
	 PULSOUT Clk_7219, 1 ; bit 15 is don't care - enable if two or more MAX7219 are cascased together
	 PULSOUT Clk_7219, 1 ; bit 14 is don't care
	 PULSOUT Clk_7219, 1 ; bit 13 is don't care
	 PULSOUT Clk_7219, 1 ; bit 12 is don't care
	DIn_7219 = bit11 : PULSOUT Clk_7219, 1
	DIn_7219 = bit10 : PULSOUT Clk_7219, 1
	DIn_7219 = bit9 : PULSOUT Clk_7219, 1
	DIn_7219 = bit8 : PULSOUT Clk_7219, 1
	DIn_7219 = bit7 : PULSOUT Clk_7219, 1
	DIn_7219 = bit6 : PULSOUT Clk_7219, 1
	DIn_7219 = bit5 : PULSOUT Clk_7219, 1
	DIn_7219 = bit4 : PULSOUT Clk_7219, 1
	DIn_7219 = bit3 : PULSOUT Clk_7219, 1
	DIn_7219 = bit2 : PULSOUT Clk_7219, 1
	DIn_7219 = bit1 : PULSOUT Clk_7219, 1
	DIn_7219 = bit0 : PULSOUT Clk_7219, 1
RETURN
Initialise7219:
  Register = Decode: Data_7219 = Dec_Digits : GOSUB ShiftTo7219 
  Register = Decode: Data_7219 = Dec_Digits : GOSUB ShiftTo7219:PULSOUT Load_7219, 1
   
  Register = Intens	 : Data_7219 = 10   :GOSUB ShiftTo7219  ' DISPLAY BRIGHTNESS
  Register = Intens	 : Data_7219 = 15   :GOSUB ShiftTo7219:PULSOUT Load_7219, 1
	 
  Register = ScanLim : Data_7219 = 1  : GOSUB ShiftTo7219 ' 0 to 1    only using 2 digits on 2nd max7219
  Register = ScanLim : Data_7219 = 7  : GOSUB ShiftTo7219:PULSOUT Load_7219, 1
	    
  Register = ShutDwn : Data_7219 = Set_On     : GOSUB ShiftTo7219 
  Register = ShutDwn : Data_7219 = Set_On     : GOSUB ShiftTo7219 :PULSOUT Load_7219, 1
		  
  Register = DigTest : Data_7219 = Set_Off	  : GOSUB ShiftTo7219 
  Register = DigTest : Data_7219 = Set_Off	  : GOSUB ShiftTo7219:PULSOUT Load_7219, 1 
RETURN
I built the led 10 digital display from scratch using some plywood and 70 leds and I used
some 5/32 solid filler cord I bought at walmart ...was going to use a cutting board but
seemed the filler cord fit better and deflected light the same
If I was going o make a another display I would use two/3 leds per segment....so the light shines = in every segment
but for this project it works fine with just one led
as always I learned alot and thanks to you all
your friend mark
 

Attachments

newplumber

Senior Member
thanks Lance
filler cord is here but I got 5/32" size and if you router out 1/8" lines ...it seems to fit in tight
https://www.walmart.com/ip/Dritz-Weltfill-Solid-Filler-Cord-6yd/43497566
and believe me I spent record breaking 1.5 hours in walmart searching for something that would
make the single led per segment spread out the most....all the videos on youtube I've seen showing DIY displays
show them using 3 or more leds per segment ....I figured why not 1? well its like snap-on vs harbor freight :)
so I will report back when i bring this display home and see how it works with the family
might keep the kids in one place for a bit :)
 

newplumber

Senior Member
Hi

I brought the unit home and played a few games ....I won at the display works awesome ...going to try perfect the code a little better
but I didn't win at the game results ... I think I was 1 win out of 10 ...which is okay ...I had more fun building it
I will still try to use different material to see if I can make the display clearer ...seems hard to see if the room is lit up bright
The picture in post #2 is just print paper covering the display...but I changed that to foam wrap and seems to be brighter
I will post any other material that will be helpful if I somehow slip and fall onto something
After that I will build a 16 digit display to help calculate the cost for me to go to Mars :)
 

lbenson

Senior Member
Ok, well ..."filler cord". Still don't know what its intended use is, but glad to know about its light-spreading properties. I like materials which can multitask.
 

techElder

Well-known member
Mark, you need these LED modules. Probably cost you about a dollar per segment. Use one for each segment of each digit. You can wire them however you want. You will need a 12V supply and driver transistors for each segment. However, the 12V could be adjusted downward for proper brightness. Choose the color, too.

Decorative 5730 3LED SMD Waterproof LED Strip Light Lamp DC 12V

Then just lay a frosted plastic or glass piece over the whole shebang.

No one will say they can't read these numbers! :D
 

newplumber

Senior Member
Ok, well ..."filler cord". Still don't know what its intended use is
I think its made to roll fabric around it ...but i'm not into sewing ...although I broke a few machines of my wife's machines trying to understand how it works
and of course testing what materials it can and can not punch thru :) ....I finally calculated it out ...its funner and cheaper testing picaxe chips


@texas ...yes good idea but I would probably use my APA102 RGB strips ...I was going to use them for a hand rail but my test results ...
( wooden rail tight inside a thin pvc tube to make it glow ) did not meet my expectations so I might redo the whole display and use the apa102s
then my digits can be 8"+ tall so in case the neighbor wants to play too ... i'll do some more testing

FWIW most of you read the directions FIRST ...but then theres ME ...which builds something ...then writes how NOT to build it
maybe I can call it UNdirections for political correctness :)
 
Last edited:

techElder

Well-known member
Hmmmm ... seems like you should have an 11-digit display to display level "1" through level "10".

Perhaps then the "current" level number could be a different color from the other displayed random levels, and the "10"th level would be two digits of the same color?

In my house, its my wife and her mother that get raucous playing Phase 10 (and anyone else dumb enough to play with them.) I was thinking perhaps you had come up with a way to eliminate the claims of "lying" and "cheating" that I often hear coming through the two closed doors and my headset when they play Phase 10. :D
 

newplumber

Senior Member
seems like you should have an 11-digit display to display level "1" through level "10".
yes I thought about making a "1" close to every digit ...but just a "0" zero works pretty good ...had no complaints on "theres no level zero??"

I was thinking perhaps you had come up with a way to eliminate the claims of "lying" and "cheating"
I guess the rules we play makes it pretty hard to cheat...plus with not knowing which level is next is a another plus


To make a 10 digit RGB display ...is going to take some time ...so I'll practice with just one digit for now see what it looks like
after looking at my apa102 rgb strips ...the leds might be to far spread out ...so i'm going to be back on drawing board
second thought is use max7219 per 2 digits with single rgb leds i already have
have to look at the data sheet see what voltage can I use with max7219
I'm trying to use 3 leds per segment with only one SEGX pin but dont think thats possible
 

techElder

Well-known member
I'm trying to use 3 leds per segment with only one SEGX pin but dont think thats possible
You are going to have to use FETs to drive your segments. You may need to invert your drive logic if you add an FET driver, because the FET will be an inverter.

FET should be 2n7000 type.
 

techElder

Well-known member
Probably put an FET on each digit drive line. I'm not sure whether your displays are common-anode or common-cathode.

What you want to do is divert the current for the LEDs from the 7219. In the process of doing that you'll be inverting that drive signal, so you'll have to account for that somewhere.
 

newplumber

Senior Member
the ones I have for my simple test are common anode
Its slow today so I'll build a 8" RGB single display with 3 rgb's per segment
I'll draw a schematic of a idea later on
I'm not at my home picaxe station so i'm limited to a few max7219s and a few uln2803s
I could just use a few 74hc595s but the max7219 seems more cool to use
I also might use the 20X2 for more speed ...I'll let you know in a bit/hours

btw I ordered the wrong rgb strips again
never heard of these but now I know :) (single color leds on a strip)
https://www.ebay.com/itm/16-4ft-2835-300SMD-RGB-DIY-LED-Strip-Light-Flexible-Car-Lamp-DC-12V/253470098815?hash=item3b03fec57f:g:rfQAAOSwEIJanbft

so I ordered some like these ...
https://www.ebay.com/itm/ABI-300-LED-Strip-Light-RGB-Color-Changing-High-Brightness-5050-5M-16-4FT-12V/362083977553?epid=8014845289&hash=item544de30951:g:1OEAAOSwsotanDI4

I will try to make the displays as big as i can to use 3 leds of the strip per segment
now back to building something which seems low potential to see the garbage can :)
 
Last edited:

newplumber

Senior Member
Okay here is my first test since I have four max7219 s
one max7219 per 2 segments
I think it might be kinda cool then I can control different colors in the segment (between 3 leds)
of course if it works ... "which if I have a problem ...it will never be MY code being the issue" :) ...or..
okay I'm joking ...its always my code but I have a 1/100000 chance this time it wont be

I have the leds in the 8" display now waiting to see if the wires will solder them selfs to all the million connections
 

Attachments

Top