random blinky leds
charricr
Posts: 1
new to programming basic stamp homework board.
have been plugging away.i have a circuit with 15 leds from the pins
and a button on pin 15
i have two loops. loop 1 blinks the leds on then off from 0 to 14 then repeates unless i hold the button in then the program goes back to the start
······················· loop 2 liinks the leds on then off from 14 to 0· then repeates unless i hold the button in then the program goes back to the start
im trying to figure out how a third loop could blink in a random order then repeates unless i hold the button in then the program goes back to the start
thepin var word
btnwrk var byte
cycles var word
loop:
button 15,0,255,250,btnwrk,0,nopress
count 15,5000,cycles
pause 500
again:
·if cycles = 1 then loop1
·if cycles = 2 then loop2
·if cycles = 3 then loop3
nopress:
· goto loop:
···· loop1:
···· for thepin = 0 to 14
···· toggle thepin
···· pause 40
···· toggle thepin
···· pause 40
·· next
·· if in15 = 1 then loop:
·goto again:
have been plugging away.i have a circuit with 15 leds from the pins
and a button on pin 15
i have two loops. loop 1 blinks the leds on then off from 0 to 14 then repeates unless i hold the button in then the program goes back to the start
······················· loop 2 liinks the leds on then off from 14 to 0· then repeates unless i hold the button in then the program goes back to the start
im trying to figure out how a third loop could blink in a random order then repeates unless i hold the button in then the program goes back to the start
thepin var word
btnwrk var byte
cycles var word
loop:
button 15,0,255,250,btnwrk,0,nopress
count 15,5000,cycles
pause 500
again:
·if cycles = 1 then loop1
·if cycles = 2 then loop2
·if cycles = 3 then loop3
nopress:
· goto loop:
···· loop1:
···· for thepin = 0 to 14
···· toggle thepin
···· pause 40
···· toggle thepin
···· pause 40
·· next
·· if in15 = 1 then loop:
·goto again:
Comments
And a MAX command which can limit an amount???
Advanced would be·the system clock, maybe·save to a variable·what it is at a certain moment. Then in the variable section of the help pages it says how to read certain "bits" of a number (1's and 0's). Perhaps you could look at certain bits of the system clock at a moment in time and from that get a random number or the "seed" for a random number.
Another advanced thing would be to count how long the button is pressed, then use that as a seed for a random number. (If possible?)
Or you could use the system clock again. Then get the last bit from that number. It would be a 1 or a 0. If a 1, turn on the next light to the right. If a 0, turn on the next light to the left. And perhaps use RANDOM and MAX to pause to display the light, then after the pause, get another system clock reading.
I should think with the last, the duration each light is on would vary as well as the direction as to which light will turn on next?
I would start by playing around with RANDOM and see what that does...
·
http://www.efx-tek.com/php/smf/index.php?topic=69.0
n.b. Will need to convert to BS2. See Parallax company site for conversion information.
cheers, David