How to turn random number into output symbol

McAlester

New Member
I'm using a 40X2 with a single input, pin D.7, and 31 outputs, A.0 through D.6. When I detect a pulse on the input I want to send a pulse to an output at random. I generate a random number, b2 = 1 to 31, each number represents one of the outputs, as follows (with symbols for the output pins):
symbol L1 = A.O b2 = 1 corresponds to output A.0
symbol L2 = A.1 b2 = 2 corresponds to output A.1
symbol L3 = A.2 b2 = 3 corresponds to output A.2
etc.

What I don't know how to do is to turn the random numbers which represent the outputs, 1 through 31, into the symbols L1 through L31 so I can use the pulsout command; for example, if b2 = 1 then I want the pulse on pin A.0:
pulsout L1, 10

Thanks for any suggestions.
McAlester
 

lbenson

Senior Member
Are you obliged to have 1 represent A.0?

If not, you're in luck, since the A.#, B.#, etc. pin designations are actually just numbers. B.0-B.7 are 0-7, C.0-C.7 are 8-15, A.0-A.7 are 16-23, and D.0-D.7 are 24-31. So you can just do your calculation and make the result be 0 through 30 (at the worst by subtracting 1 from the answer you are already getting). If the result is in b2, you can then just say HIGH b2: PAUSE pausetime: LOW b2 (or use PULSOUT).

As an example, try this in the simulator:
Code:
for b2 = 0 to 31
  high b2
  pause 250
next b2
do: loop ' so the result will remain visible
If you're committed to starting with A.0, you can do a LOOKUP.
 
Last edited:

McAlester

New Member
No, I'm not obliged to have 1 represent A.0, but I am greatly obliged to you for your help - that solution is perfect. I can shift my random numbers to 0 through 30.

I tried your code just now and I see how it works.

I didn't know that the pin designations were numbers.

[Come to think of it, if I wanted, I could shift my input to D.7 and use A.0 as an output.]

Thanks,
Mike
 
Top