hi, I have a radio very old and it has two switches one is called hundreds, the other is called fractions . The hundreds have six (6) contacts, the fractions have fifteen (15) contacts. Both connections are random. You most likely will never have a change in both switches simultaneously. I plan on using a Mega2560. The fractions will be connected to pins 22 - 37 and hundreds 40 - 46.
I understand that I can set the pins to input with internal pull ups [ pinMode( 41, INPUT_PULLUP); ]. It would be nice to have two interrupts from the two groups of switches as well, and I have to have some sort of de-bounce as well.
but i am not sure where to go...
Thanks
~~Cris H.
I suppose a schematic is out of the question ?
Do you know how these switches are wired ?
schematic think of them as two multipole switches that any pole can be open or closed at any time that is with the rotation of the switch... the goal is to figure out the switch code... LOL here is a link to the beast..http://www.phoenixcomm.net/~phnx2000/sim/catalog/chcm/images/C-3436.jpg
the only thing that I am working with is the two switches in the middle...
~~Cris
ie that means we have 21 pulled up inputs...
OMG. Military grade ? You need analog switches but you can't use them without knowing the voltage on the switch pins. If you can map the switches with power on and write the voltage on each pin when you turn the knob you could find out if analog switches would work but without those voltages I would even consider it.
This question has been asked a lot before
See http://www.arduino.cc/en/Tutorial/ShiftIn
or use analogue MUX
But as you are reading switches that are either ON or OFF and not a variable in between, Shift In, seems the more logical solution
I could be wrong but if I am not mistaken , the "ILS" means if came out of an aircraft and it is the Instrument Landing System and may be a lot more complex than you suspect.
phoenixcomm:
It would be nice to have two interrupts from the two groups of switches as well, and I have to have some sort of de-bounce as well.
Then you are very confused indeed about the purpose of interrupts; or even the meaning of the term itself. And your original description of "I need to read Lots of pins at once" is in fact totally incorrect in computer terms.
And the mantra I so often find it necessary to repeat - It is one of the most common misunderstandings for "newbies" to think that an interrupt is a means to alter the flow of the main program. In fact, the very opposite is the case, an interrupt is designed such that a brief but important operation which must and can be processed immediately will be performed without affecting the flow of the primary program in any way.
This is not to be confused with the consequence that something that the ISR does may later be consequential to the main program as it continues to process its various tasks. This is equally true of a multi-tasking OS where an interrupt may result in task-switching but nevertheless on resumption, the immediate course of each task is as a matter of definition, unaffected
In general, it makes the most sense to use a couple of shift registers.
But we really are not sure of what it is you want to do in the first place. Presumably you are going to "recycle" the switches from that disposals radio for a different purpose, to input numbers into something else. If you care to explain just what that new purpose is, it would make it much easier to suggest the best way to do it as it relates to how fast you expect a response, how to wire it (for example, if the switches are only to be connected to the Arduino, it makes sense to "multiplex" the two switches so that the six positions of the 6-way overlay the 15-way and you need only 16 or at most, 17 connections.
You need to look at the switches what voltage is produced at each switch position? I think you need just 2 analog inputs (big clue - its very old ......)
Mark
If you want to use digital inputs then go ahead, you have plenty on the Mega.
If you want an interrupt so that you have an automatically updated value from the switch then you can use the pin change interrupt mechanism.
However you do not need an interrupt and in fact it will make things more complex to no advantage. You just need to know what the switch value is in certain parts of your project so it is easy enough to write a function that scans the inputs and build up the number when you need it rather than keep track of the number when you don't need it.
You will almost certainly need to use arrays to do the scanning, so see here for how to use them if you are not sure.
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html
raschemmel, rogerClark: No Not Analog!! I am using pinMode( x, INPUT_PULLUP) so that each pin is pulled up when open...
Paul __B: No Not REMOVE; use it as is!!, and Paul I have been writing Real-Time C /Unix/Linux for a lot of years (a few decades)!! Newbie, C no Arduino yes... And btw I did mean interrupts please look at the Unix/Linux select call. And one more thing " I need to read Lots of pins at once" is exactly what I want to do! And If you had read my post you would have seen that I am going to use an Arduino Mega2560 with EACH pin going to its own input pin! No Muxing, No Muss, No Fuss!!
Grumpy_Mike: Thank you but thats out put not input... I have to work out the truth table for the switches as I do not have a pinout (I made one, but I does not tell me the outputs). So far I have gotten here...
int fraction[] = { 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 };
int hundred[] = {40, 41, 42, 43, 44, 45 };
int hund_val[15];
int fract_val[6];
void setup(){
int i, n;
// Fraction Pins
for( i = 0; i < 15; i++) {
pinMode(fraction[i], INPUT_PULLUP);
}
// Hundred Pins
for( i = 0; i < 6; i++) {
pinMode(hundred[i], INPUT_PULLUP);
}
// On-Off Switch
pinMode( 50, INPUT_PULLUP);
}
void loop() {
int i;
??? how to figure out which group is moved?? (select)
if( fraction ) {
for( i = 0; i < 16; i++ ) {
fract_value[i] = digitalRead(fraction[i]; }
if ( hundred ) {
for( i = 0; i < 7; i++ ) {
hund_value[i] = digitalRead(hundred[i]; }}
}
Thank you but thats out put not input.
It makes no difference what you are doing the principle of using arrays is exactly the same. You hold the pin numbers in an array. But you seem to be doing that anyway.
how to figure out which group is moved??
You read in the latest values from all the switches and compare them with the values you read in last time.
If you can arrange for the pins to be on complete ports, then you can read the pins in groups using direct port manipulation:
The fractions will be connected to pins 22 - 37: 16 bits
and hundreds 40 - 46: 7 bits
fractionsLow = PINB;
fractionsHigh = PINC;
fractions = word (fractionsHigh, fractionsLow);
hundreds = PIND & 0b01111111;
Looking at the Mega schematic, ports A, B, C, F, K, L all appear to be accessible to users as complete ports.