Random output pin generator
johnags
Posts: 7
in BASIC Stamp
I'm using a BS2 with PBasic. I would like a super small bit of code that will allow a single input pin to run a random out put to one of nine pins. Each single input would turn on a different out pin each time. I'm trying to make an electronic wind chime. Any ideas would be much appreciated.
Comments
Edit: Should have said PULSOUT, rather than Pulse.
Be aware: You likely cannot directly drive the chime plungers from BS-2 pins. You will likely need at least a buffer of some sort or even a relay. EndEdit
trigger PIN 1 ' push button or other.
chimes CON 7 ' does output to pins 7 through 15 based on divider.
led VAR Word ' chimes here will produce an error, symbol already defined.
Temp VAR Word
start:
DO WHILE trigger = 0
LOOP
RANDOM led
Temp = led // 9
PULSOUT chimes+Temp, 2000 ' A period number must be here, it regulates brightness, signal strength.
PAUSE 30 ' This gives a time delay between pin "on", also delays multiple pin "on" for short inputs.
GOTO start
' Random is relative, but really good enough.
Now all I need to do is turn this output into a gosub bit of code. In other words random output starts a random bit of code from a list.
Thanks.
Anyone who attempts to generate random numbers...is living in a state of sin. von Neumann