Is it posible to ranomly switch on 2 output pins on a 28x2

Phil bee

Member
Hi Guys, how would i go about seting 2 outputs high out of 8 possible outputs on 1 port in a random patern.
Any ides would be helpful. This is to try automating the 5x5x5 led cube that i have made.

Thanks for any help.
 

premelec

Senior Member
It's certainly possible but to get some effect that you have in mind will take more thought and planning - e.g. how long minimum and maximum between changes? If you want more nearly actual random values you should review previous discussions of random function on this forum past and recent. You can use logical functions to set your pins - e.g. IF rand > 45 and rand < 131 THEN TOGGLE pins... etc... and then delay how often this happens - perhaps by a 'random' delay if you want to - it may take a bit of fiddling to get a pleasing outcome... So you keep sampling for a random value and occasionally do your comparisons and pins high or low instruction... Is this what you have n mind?
 

Bill.b

Senior Member
This is part of my code to generate a random pattern on a 4 x 4 x 4 cube.

A 5 x 5 x 5 cube gernerally use serial output to a LED driver for the x y drive, as there are insufficient outputs on a 28x2 (30 outputs required).


Code:
symbol outputb	= b7
symbol outputc	= b6
symbol looptme 	= w10
symbol delay2	= b11
delay2 = 50
randompattern:	
for b8 = 1 to delay2
	random w3
	
for looptme = 1 to 10

	pinsb = outputc
	pinsc = outputb
	pinsa = %00000001
	pause 5
next looptme
	random w3
	
for looptme = 1 to 10

	pinsb = outputc
	pinsc = outputb
	pinsa = %00000010
	next looptme
	pause 5
	random w3
	for looptme = 1 to 10

	pinsb = outputc
	pinsc = outputb
	pinsa = %00000100
	next looptme
	pause 5
	random w3


for looptme = 1 to 10

	pinsb = outputc
	pinsc = outputb
	pinsa = %00001000
	next looptme
	pause 5


	next b8
	return
Bill
 

Phil bee

Member
Thanks for the ideas, Bill.b my cube is running on a 40x2 with 5 npn transistors providing the layer drive current and works quite well
but i would like to get some better paterns running.

Premelec i think that your idea is probably more like what i'm after but as my proggraming skils are about zero i'm not sure how i would write it in basic.

Regards Phil.
 

Phil bee

Member
Here is the code that I have running at the moment.
A logic 1 turns the Led off and logic 0 turns the led or layer transistor on, layers are on pins d.1 to d.5


Code:
#picaxe40x2
#no_data
#no_table

dirsa=%11111111
dirsb=%11111111
dirsc=%11111111	'Set up ports as output
dirsd=%00111111


Main:
setfreq m8


Gosub Letter_m
Gosub Blank
pause 50
Gosub Letter_e
Gosub Blank
pause 50
Gosub Letter_r
Gosub Blank
pause 50
Gosub Letter_r
Gosub Blank
pause 50
Gosub Letter_y
Gosub Blank
pause 50
Gosub Blank
pause 50
Gosub Letter_c
Gosub Blank
pause 50
Gosub Letter_h
Gosub Blank
pause 50
Gosub Letter_r
Gosub Blank
pause 50
Gosub Letter_i
Gosub Blank
pause 50
Gosub Letter_s
Gosub Blank
pause 50
Gosub Letter_t
Gosub Blank
pause 50
Gosub Letter_m
Gosub Blank
pause 50
Gosub Letter_a
Gosub Blank
pause 50
Gosub Letter_s
Gosub Blank
Pause 200
gosub star
pause 20
Gosub Blank
Pause 150
gosub rand_dot
gosub blank
Pause 150


flash:
let b6=0
setfreq m1
For b1= 40 to 3 step-1
Pinsa=%11000000
Pinsb=%00111001
Pinsc=%00000111
Pinsd=%11010100
pause b1
Pinsa=%11111111
Pinsb=%11111111
Pinsc=%11111111
Pinsd=%11111111
pause b1
next b1
do
Pinsa=%11000000
Pinsb=%00111001
Pinsc=%00000111
Pinsd=%11010100
pause b1
Pinsa=%11111111
Pinsb=%11111111
Pinsc=%11111111
Pinsd=%11111111
pause b1
inc b6
loop until b6=20

SQUARE1:

setfreq K500

let b5=2		

Pinsa=%11000000
Pinsb=%00111001
Pinsc=%00000111

Pinsd=%11111100
pause 2
Pinsd=%11111010
pause 5
Pinsd=%11110110
pause 5
Pinsd=%11101110
pause 5
Pinsd=%11011110
pause 5
Pinsd=%11101110
pause 5
Pinsd=%11110110
pause 5
Pinsd=%11111010
pause 5
Pinsd=%11111100
pause 3

'xxxxxxxxxxxxxxxxxxx

CROSS:

Pinsa=%01111011
Pinsb=%10000011
Pinsc=%10111101

Pinsd=%11111101
pause 2
Pinsd=%11111011
pause 5
Pinsd=%11110111
pause 5
Pinsd=%11101111
pause 5
Pinsd=%11011111
pause 5
Pinsd=%11101111
pause 5
Pinsd=%11110111
pause 5
Pinsd=%11111011
pause 5
Pinsd=%11111101
pause 3

Pinsa=%11111111
Pinsb=%11111111
Pinsc=%11111111
Pinsd=%00111111

'xxxxxxxxxxxxxxxxxxxxx

ROTATING_ARROW:

For b1= 15 to 5 step-1
setfreq k500
let b6=0
do

pause b1
Pinsa=%11100111
Pinsb=%11101100
Pinsc=%11101110
Pinsd=%00000001
pause b1
Pinsa=%00111011
Pinsb=%11101110
Pinsc=%10111101
Pinsd=%00000001
pause b1
Pinsa=%10011100
Pinsb=%11101111
Pinsc=%11111011
Pinsd=%00000000
pause b1
Pinsa=%10111111
Pinsb=%10000011
Pinsc=%11111110
Pinsd=%00000001
pause b1
Pinsa=%11101111
Pinsb=%01101110
Pinsc=%11001110
Pinsd=%00000001
pause b1
Pinsa=%01111011
Pinsb=%11101111
Pinsc=%10111000
Pinsd=%00000001
pause b1
Pinsa=%10111110
Pinsb=%11101111
Pinsc=%01110011
Pinsd=%00000000
pause b1
Pinsa=%11111111
Pinsb=%10000010
Pinsc=%11111011
Pinsd=%00000001
inc b6
next b1
loop until b6=3
pause 10
gosub blank
Pause 50
Goto Main





'xxxxxxxxxxxxxxxxx Blank
Blank:

Pinsa=%11111111
Pinsb=%11111111
Pinsc=%11111111
Pinsd=%11111111
Pinsa=%11111111
Pinsb=%11111111
Pinsc=%11111111
Pinsd=%11111111
return
'xxxxxxxxxxxxxxxxx M
Letter_M:

let b6=0
do
Pinsa=%10001110
Pinsb=%00101000
Pinsc=%11100111
Pinsd=%00110100
inc b6
loop until b6=150
return
'xxxxxxxxxxxxxxxxxx E
Letter_E:

let b6=0
do
Pinsa=%11110001
Pinsb=%11001110
Pinsc=%00011011
Pinsd=%00110101
inc b6
loop until b6=150
return
'xxxxxxxxxxxxxxxxxx R
Letter_R:

let b6=0
do
Pinsa=%10110001
Pinsb=%11001110
Pinsc=%01101010
Pinsd=%00110101
inc b6
loop until b6=150
return
'xxxxxxxxxxxxxxxxxx Y
Letter_Y:

let b6=0
do
Pinsa=%10110101
Pinsb=%11101110
Pinsc=%10111101
Pinsd=%00110101
inc b6
loop until b6=150
return
'xxxxxxxxxxxxxxxxxx C
Letter_C:

let b6=0
do
Pinsa=%11111000
Pinsb=%11011110
Pinsc=%10001011
Pinsd=%00110101
inc b6
loop until b6=150
return
'xxxxxxxxxxxxxxxxxx H
Letter_H:

let b6=0
do
Pinsa=%10110101
Pinsb=%11000110
Pinsc=%01011010
Pinsd=%00110101
inc b6
loop until b6=150
return
'xxxxxxxxxxxxxxxxxx I
Letter_I:

let b6=0
do
Pinsa=%01111011
Pinsb=%11101111
Pinsc=%10111101
Pinsd=%00110101
inc b6
loop until b6=150
return
'xxxxxxxxxxxxxxxxxx S
Letter_S:

let b6=0
do
Pinsa=%11111000
Pinsb=%11101110
Pinsc=%00111110
Pinsd=%00110100
inc b6
loop until b6=150
return
'xxxxxxxxxxxxxxxxxx T
Letter_T:

let b6=0
do
Pinsa=%01100000
Pinsb=%11101111
Pinsc=%10111101
Pinsd=%00110101
inc b6
loop until b6=150
return
'xxxxxxxxxxxxxxxxxx A
Letter_A:

let b6=0
do
Pinsa=%10111011
Pinsb=%11000110
Pinsc=%01011010
Pinsd=%00110101
inc b6
loop until b6=150
return

'xxxxxxxxxxxxxxxxx Star
Star:
setfreq k500
let b6=0
do
Pinsa=%01011011
Pinsb=%11000101
Pinsc=%11101010
Pinsd=%00111100
pause 5
Pinsd=%00111010
pause 5
Pinsd=%00110110
pause 5
Pinsd=%00101110
pause 5
Pinsd=%00011110
pause 5

Pinsd=%00101110
pause 5
Pinsd=%00110110
pause 5
Pinsd=%00111010
pause 5
Pinsd=%00111100
pause 5
inc b6
loop until b6=4
setfreq m8
return

'xxxxxxxxxxxxxxxxxxxxxxxx

RAND_DOT:

setfreq k500
let b6=0
do
random w10
pinsd = b21
pinsa = b20
pinsb = b21
pinsc = b20
random w10
pause 10
pinsd = b20
pinsa = b20
pinsb = b21
pinsc = b20
random w10
pause 10
pinsd = b21
pinsa = b20
pinsb = b21
pinsc = b20
random w10
pause 10
pinsd = b20
pinsa = b20
pinsb = b21
pinsc = b20
random w10
pause 10
pinsd = b21
pinsa = b20
pinsb = b21
pinsc = b20

inc b6
pause 10
loop until b6=12
setfreq m8
return

'xxxxxxxxxxxxxxxxxxxxxxx
 
Last edited:
Top