help with program
rr
Posts: 63
hello...
i have created a circuit with one button and twelve npn transistors that switch clusters of leds. the button is on pin 0 and the transistors are on pin 1 through 12. the circuit uses a bs2 oem.
i would like to create a program that works like this:
when a person pushes the button the transistors will randomly be switched on and off one at atime untill all the transistors have been on. At the end of the sequence one of the transitors wll randomly switch on·and and blink for 5 seconds then turn off.
basically what i have done is built a decsion maker. i have 12 ligh boxes with words on them and they are back lit with leds. when a viewer pushes the button i want the machine to light up each word randomly for about 2 seconds and then in the end randomly blink one of the words(the answer) for about five seconds.
i know that i can use the random comand and an exteral button with decent random results.·with the random variable i know i can randomly light up the boxes but how do i randomly light up the all the 12 boxes without repeating.
i would like to make the program as random as possible...
any hints, suggestions or ideas would be great.
i greatly value all the help...
·
i have created a circuit with one button and twelve npn transistors that switch clusters of leds. the button is on pin 0 and the transistors are on pin 1 through 12. the circuit uses a bs2 oem.
i would like to create a program that works like this:
when a person pushes the button the transistors will randomly be switched on and off one at atime untill all the transistors have been on. At the end of the sequence one of the transitors wll randomly switch on·and and blink for 5 seconds then turn off.
basically what i have done is built a decsion maker. i have 12 ligh boxes with words on them and they are back lit with leds. when a viewer pushes the button i want the machine to light up each word randomly for about 2 seconds and then in the end randomly blink one of the words(the answer) for about five seconds.
i know that i can use the random comand and an exteral button with decent random results.·with the random variable i know i can randomly light up the boxes but how do i randomly light up the all the 12 boxes without repeating.
i would like to make the program as random as possible...
any hints, suggestions or ideas would be great.
i greatly value all the help...
·
Comments
Reset:
· flags = 0
Main:
· DO
··· RANDOM selection
· LOOP UNTIL (Play = Pressed)
Get_Card:
· theCard = selection // 12················· ' create card #, 0 - 11
· IF (flags.LOWBIT(theCard) = 1) THEN······· ' already been seen?
··· RANDOM selection························ ' yes, tumble again
··· GOTO Get_Card··························· ' get new card
· ELSE
··· flags.LOWBIT(theCard) = 1··············· ' mark card
· ENDIF
·
Show_Card:
· HIGH theCard
· PAUSE ShowTime
· LOW theCard
· IF (flags < %0000111111111111) THEN Main
Final_Card:
· RANDOM selection
· theCard = selection // 12
· FOR idx = 1 TO 6
··· TOGGLE theCard
··· PAUSE FlashRate
· NEXT
· GOTO Reset
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 8/23/2005 1:16:47 PM GMT
To solve this problem and make the routine seem more random would be to instead of setting a bit for each answer each time through, you could use a byte counter and increment that byte counter each time the light was selected. Instead of checking if it has been seen you can use another random generator to determin if that box should be selected by using the incremented byte value, taking 10% of that value and getting a random number from the range of the byte. If the number is within the 10% it would use that light again. Using a third random generator for the percentage range of the byte could also be used.
Example:
Light 1 has been shown once, add 10 to byte counter (instead of setting bit flag) - do random on that value of 10, if the number is 1 show it again, byte counter adds 10 and is now 20, if its hit again random on 20 and if its less than 10% of 20 (2) show it again. By using a random number instead of fixed 10% you would start to get a much better random selection but still weighted twards the lights that have not yet been selected so they all will be shown but with previous ones popping up out of the blue.
Set 24 bytes of memory aside for 2 - 12 element arrays (like 2 decks of cards of 12 cards)
Plase numbers 1 through 12 in the first 12 locations and 1 - 12 in the second array
When your program starts do a shuffel like a deck of cards like this
for i=1 to 100
x=random(12)
y=random(12)
tmp=array(x) 'swap
x=array(y)
y=tmp
next
do the same for the second array
During your program start with array#1 and just use the values stored starting with array#1(1) thru array#1(12)
Do a swap routine on the unused array in between lines of your other code.
Next game use array#2 and do the swapping on array#1 during program execution
That way you have instant random numbers without all that searching for the next random number.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
in your code you have a line...
IF (flags < %0000111111111111) THEN Main
wouldnt this be for out puts 4 through 15???
wouldnt i want...
IF (flags < %1111111111110000) THEN Main
for outputs 0 through 11????
also i like metron's ideas but it is a little over my head...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
DEBUG BIN16 anyValue
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com