Has anyone written a program that scans a set of switches to see which ones are on?
HalloweenBob
Posts: 2
I want to make a program that will scan 12 switches continuously, and determine how many and which ones are on at any given time.
The switches are wired individually, but could be wired in a matrix if that would help.
Then after gathering that information, I need it to output by closing a matching set of switches in rapid succession.
It should work like this:
1. It polls all the inputs and determines which switch or switches are closed at any given time.
2. The output of the circuit is a rotating series of quick switch closures representing each switch that is closed at it's input. I need 12 outputs from this circuit. each output is a set of normally open contacts which become closed (0 ohms) in order to 'short out' the contacts of a button on a transmitter.
So, as described earlier, this circuit would poll the input switches. As an example, I am going to say that inputs 3, 4, 7 and 8 are all closed at the time of the polling.
The output of this circuit needs to behave as follows: It needs to create a zero ohm connection between the two output wires for outputs 3,4,7 and 8 in the following manner:
Output 3 is closed for 200ms
Output 3 is then opened and there is a 50ms delay
Output 4 is closed for 200ms
Output 4 is then opened and there is a 50ms delay
Output 7 is closed for 200ms
Output 7 is then opened and there is a 50ms delay
Output 8 is closed for 200ms
Output 8 is then opened and there is a 50ms delay
REPEAT this pattern for as long as the input state remains the same.
I am just guessing at the 200ms and the 50ms times. I would like to have the ability to adjust those times so that I can discover what the optimal times are. I am assuming that there might be a problem if there is no delay time in-between releasing one button and pushing another. With no delay at all, my transmitter may get confused, and not be able to react fast enough to open the first connection before the second one is made locking it out.
To explain about the transmitter....
I have a transmitter with 12 buttons on it. I have removed the buttons and attached bare wires where they were. Connecting any of those wires to GND on the transmitter completes the circuit and for all purposes, closes the switch. When a switch is closed, the associated relay in the receiver is energized as you would expect. Not complicated. Push button 3 and relay 3 becomes energized wirelessly.
The problem is this transmitter can only send one signal at a time. The switches are all momentary switches, so if I press and hold switch one, Relay one closes, but while I'm holding down switch one, I can not energize any other relays. Pushing additional buttons at the same time does nothing.
I want to 'pulse' the buttons so that each button that I want to hold down at the same time, gets pressed quickly, then the next, then the next and then repeats with short pauses between them.
Hopefully I have explained this well enough.
I am completely new to the basic stamp world, but understand programming of this sort well enough to take something that exists and modify it to suit me. I am fairly sure I am not the first person to need something like this, so if you have already invented this wheel, please share if you will to give me someplace to start.
Thank you!
The switches are wired individually, but could be wired in a matrix if that would help.
Then after gathering that information, I need it to output by closing a matching set of switches in rapid succession.
It should work like this:
1. It polls all the inputs and determines which switch or switches are closed at any given time.
2. The output of the circuit is a rotating series of quick switch closures representing each switch that is closed at it's input. I need 12 outputs from this circuit. each output is a set of normally open contacts which become closed (0 ohms) in order to 'short out' the contacts of a button on a transmitter.
So, as described earlier, this circuit would poll the input switches. As an example, I am going to say that inputs 3, 4, 7 and 8 are all closed at the time of the polling.
The output of this circuit needs to behave as follows: It needs to create a zero ohm connection between the two output wires for outputs 3,4,7 and 8 in the following manner:
Output 3 is closed for 200ms
Output 3 is then opened and there is a 50ms delay
Output 4 is closed for 200ms
Output 4 is then opened and there is a 50ms delay
Output 7 is closed for 200ms
Output 7 is then opened and there is a 50ms delay
Output 8 is closed for 200ms
Output 8 is then opened and there is a 50ms delay
REPEAT this pattern for as long as the input state remains the same.
I am just guessing at the 200ms and the 50ms times. I would like to have the ability to adjust those times so that I can discover what the optimal times are. I am assuming that there might be a problem if there is no delay time in-between releasing one button and pushing another. With no delay at all, my transmitter may get confused, and not be able to react fast enough to open the first connection before the second one is made locking it out.
To explain about the transmitter....
I have a transmitter with 12 buttons on it. I have removed the buttons and attached bare wires where they were. Connecting any of those wires to GND on the transmitter completes the circuit and for all purposes, closes the switch. When a switch is closed, the associated relay in the receiver is energized as you would expect. Not complicated. Push button 3 and relay 3 becomes energized wirelessly.
The problem is this transmitter can only send one signal at a time. The switches are all momentary switches, so if I press and hold switch one, Relay one closes, but while I'm holding down switch one, I can not energize any other relays. Pushing additional buttons at the same time does nothing.
I want to 'pulse' the buttons so that each button that I want to hold down at the same time, gets pressed quickly, then the next, then the next and then repeats with short pauses between them.
Hopefully I have explained this well enough.
I am completely new to the basic stamp world, but understand programming of this sort well enough to take something that exists and modify it to suit me. I am fairly sure I am not the first person to need something like this, so if you have already invented this wheel, please share if you will to give me someplace to start.
Thank you!
Comments
This assumes you do not have a matrix of switches. If you have that, then you could read more switches with less inputs, but the method of determining which switch is on would be different.
This also assumes a switch that is on generates a high input, and you turn an output on (high) to drive the relay closed.
The relays are connected to P0-P7 as outputs in order (i.e. P0 = relay 1, P1 = relay 2)
The switches are connected to P8-P15 as inputs in order (i.e. P8 = switch 1, P9 = switch 2)
Prophead mentioned the propeller.
Would this be what you are talking about? http://parallax.com/product/32150
What else would I need if I bought that propeller board, or am I looking at the wrong one?
And as for the program posted by Sapphire, Thank you! I would need 12 inputs and outputs for sure.
What other components would I need to achieve that? If I can do it equally well with the propeller or the BS, I might as well choose the option with the fewest parts and lowest cost. Which would be the way to go out of these options. Or is there yet another option that I haven't even thought of yet?
Thanks for the fast helpful responses!