randomness
Archiver
Posts: 46,084
I am designing something that has 9 LEDs on it and I will want to randomly
turn some subset on. In other words, my program will decide that at this
time 6 of them should be lit. I want to choose 6 at random to light. Then,
at some other time, I will want to select 7 at random to light.
Any ideas about how to write the software to select the LEDs?
thanks
bob
[noparse][[/noparse]Non-text portions of this message have been removed]
turn some subset on. In other words, my program will decide that at this
time 6 of them should be lit. I want to choose 6 at random to light. Then,
at some other time, I will want to select 7 at random to light.
Any ideas about how to write the software to select the LEDs?
thanks
bob
[noparse][[/noparse]Non-text portions of this message have been removed]
Comments
A) Generate random number between 0 and 8 (use RANDOM function)
Turn on LED #0 to #8 -- if not already on
C) Increment counter
D) If counter at max, you're done
Here's a bit of PBASIC that may help:
Light_Leds:
ledsOn = 0
OutL = %00000000
Out8 = %0
lastLed = 15
DO
RANDOM rndNum
theLed = rndNum.Nib1 */ $89 ' convert 0 - 15 to 0 - 8
IF (theLed <> lastLed) THEN
Outs.LowBit(theLed) = 1
ledsOn = ledsOn + 1
lastLed = theLed
ENDIF
LOOP UNTIL (ledsOn = numLeds)
Please note that I wrote this off the top of my head ... you'll have to test
it and fill in the rest.
-- Jon Williams
-- Parallax
In a message dated 5/6/2003 3:53:02 PM Central Standard Time,
eclecticrr@A... writes:
> I am designing something that has 9 LEDs on it and I will want to randomly
> turn some subset on. In other words, my program will decide that at this
> time 6 of them should be lit. I want to choose 6 at random to light.
> Then,
> at some other time, I will want to select 7 at random to light.
>
> Any ideas about how to write the software to select the LEDs?
>
> thanks
>
> bob
[noparse][[/noparse]Non-text portions of this message have been removed]