Random output pin generator

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.


  • 6 Comments sorted by Date Added Votes
  • tomcrawfordtomcrawford Posts: 837
    edited July 2017 Vote Up0Vote Down
    maybe something like this to get you started
    Trigger  PIN   I/ONumber of "single Input Pin"
    Chimes  CON    I/ONumber of first of nine contiguous output pins
    RNum    VAR    Word
    Temp     VAR    Word
    do while Trigger = 0     'wait for the single input
    Random RNum            'choose an output
    Temp = RNum // 9          'zero through eight
    Pulse Chimes+Temp, period    'send a pulse to one of the chimes
    goto top

    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
    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
    Cool, CA, USA 95614
  • Thanks I will give it a try. I'm driving opto-isolators to dive LED strips.
  • Two of my favorite BS2 multi-pin rhythmic videos from the same guy, for inspiration. Not random by any means!

    "When you make a thing, a thing that is new, it is so complicated making it that it is bound to be ugly. But those that make it after you, they don’t have to worry about making it. And they can make it pretty, and so everybody can like it when others make it after you."

    - Pablo Picasso
  • Fun stuff!! reminds me of my elevator guy days!!
  • Tom, here is my run at your random code.
    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
    DO WHILE trigger = 0
    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.
  • :thumb:

    Anyone who attempts to generate random numbers...is living in a state of sin. von Neumann

    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
    Cool, CA, USA 95614
Sign In or Register to comment.