# randomizing port address using SF

Status
Not open for further replies.

#### MrDEB

##### Well-Known Member
Am finishing up my mexican train project and need to get going on Christmas project.
Utilizing an 18F24K20 pic and a bi colored matrix I want to utilize the red and green leds.
The red cathodes connected to port B and the green cathodes to port A
I want to, if possible, using a random number generator ( 0 to 1) change port designation, not the port bits which are changed while scrolling the letters.

#### Les Jones

##### Well-Known Member
One way that should work is based on an idea I saw some time ago. It was a circuit for creating a filickering candle effect It consisted of two free running oscillators. One running at a high frequency (Several hundred KHZ) and a low frequency one running at several tens of HZ. The high frequency went to the D input of a flipflop which was clocked bu the low frequency. You could do a simiiar thing by having a high frequency oscillator (A 555 or a CMOS gate connected as an oscillator.) and reading the state of its output from time to time during your program. The state of it's output should be faily random when you read it.

Les.

#### MrDEB

##### Well-Known Member
have no room for second oscilator. Basically want to for example
my green leds are on port A and red leds on port B
while scrolling Merry Christmas the letter M has 3 red leds on and x number of green leds on. The next time the letter M scrolls it has all red leds but two green etc.
Started code experiments trying a constant array that changes the port address (either A or B)

#### Les Jones

##### Well-Known Member
You could Google "random number generator code pic" and use it in your code. You could use a few bits of the random number to decise which LEDs to use.

Les.

#### MrDEB

##### Well-Known Member
I think I have solution basically same as your suggestion. going to program a pic and experiment with it.
My matrix has red and green leds but the battery is only 3v. Looking at similar project at Brads Projects, he doesn't have resistors on the 8 anodes. Not sure about doing this. Online calculators and using ohms law it indicates I need at least a 47 ohm resistor but Brads project runs fine without, feeling that the battery is only 3v to start with and the leds forward voltage is 1.8 for red and 2.3 for green.
ordered boards and included resistors, thinking going with 30 -50 ohm??
If anyone wants the board design files for Christmas presents let me know.

#### djsfantasi

##### Member
I needed a random-number on an Arduino before I found the random function(). My notes say that I considered this method. Connecting an analogue input pin to the collector of a transistor, with the emitter grounded and base open helps to make a noisy input. Then do an analog read on the pin.

#### JonSea

##### Well-Known Member
Swordfish Basic has a random function. That's not MrDEB's problem.

#### MrDEB

##### Well-Known Member
My problem is MIXING red and green pixels in same cluster of bytes.
loading the ROW bytes (top to bottom) bytes using a const array but inserting green and red within the mix
the colums (left to right) have no bearing on the pixel colors.
example: one row has a red led every even pixel and green led every odd pixel
thinking using the random number module then using odd as green and red as even.

#### MrDEB

##### Well-Known Member
Well I got my matrix wired up and attempting to get the compiler to compile the code.
Something to do with the internal oscillator and using the 18F24K20 pic
code compiles using 18F2420. I am using updated Inter rev1.bas which has the 18F24K20
missing something as when I attempt to compile it says OSC not declared
DEVICE = 18F24k20
CLOCK = 8

INCLUDE "Inter rev1.bas"
INCLUDE "convert.bas"

INCLUDE "SetDigitalIO.bas" // Include this file when we compile so that we can use keywords like 'setalldigital'
INCLUDE "utils.bas"

Status
Not open for further replies.