# switch combination

im trying make a combination with three 3-positions switch but i can figures how i can make it

``````if ((interrupt1 == true) && (interrupt2 == true) && (interrupt3 == true)) {
Serial.println("FOI");
}

interrupt1 = true;
Serial.println("interrupt1");
}
else {
interrupt1 = false;
}
interrupt2 = true;
}
else {
interrupt2 = false;
}
interrupt3 = true;
}
else {
interrupt3 = false;
}
``````

How are the switch wired? Where is the rest of the code? What does the code actually do? What is the code supposed to do?

How are your 3-position switches wired up? If each switch has 3 digital input pins and you have 3 of those switches, you have 9 digital inputs so 2^9 = 512 combinations.

What are you trying to do?

When you add debug Serial prints at different points in the code, do you get expected values ?

first switch in pin 8-9, second in pin 10-11, thrid in pin 12-13

``````const int int1 = 8;
const int int2 = 9;
const int int3 = 10;
const int int4 = 11;
const int int5 = 12;
const int int6 = 13;
``````

im trying "do something" when start combination with second switch in some postition, after first switch in another position, and last in another position

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Posting images:

Nimb:
first switch in pin 8-9, second in pin 10-11, thrid in pin 12-13

``````const int int1 = 8;
``````

const int int2 = 9;
const int int3 = 10;
const int int4 = 11;
const int int5 = 12;
const int int6 = 13;

``````

im trying "do something" when start combination with second switch in some postition, after first switch in another position, and last in another position

``````

Here's tips to save your fingers and mind;

Variables can be grouped together and accessed by number as an array.

``````const byte number[] = { 8, 9,10, 11, 12, 13 };  // byte can hold 0 to 255 in half the space of an int
const char number[] = { -1, 0, 1 };  // char can hold -128 to 127, used in ASCII text codes
``````

https://www.arduino.cc/reference/en/language/variables/data-types/array/

But for true/false groups your friends are the bits in integer variables and being able to Serial.print( x, BIN ) to see the 0's and 1's.

If I write decimal 321 it is ( 3 x 100 ) + ( 2 x 10 ) + ( 1 x 1 ).

If I write binary 111 it is ( 1 x 4 ) + ( 1 x 2 ) + ( 1 x 1 ) = decimal 7.

Those 3 switches corresponding to those 3 bits make a number from 0 to 7, 8 possibilities.
A switch-case statement can handle that quick and clean. Value 5 = 101 = true, false, true.

If you wire your switches to 3 pins on the same port, you can read them all at once with a port read 5x faster than Arduino digitalRead() can get just one. There are 1 or 2 bitwise logic operations (clear all but the 3 bits we care about and maybe shift those bits to positions 0, 1 and 2 so they count as binary 1's, 2's, 4's.

With an Uno you have 3 ports that can read/write 6 pins at once. The Mega has many ports you can read/write 8 pins at once.

You can work 8, 16, 32 T/F bits at a time using byte, word and unsigned long variables. Signed variables can be a pain, use unsigned. You could have 32 switch "passwords".

Arduino Language Reference, good bookmark!
https://www.arduino.cc/reference/en/

Cosine Kitty's Bitmath Tutorial
https://playground.arduino.cc/Code/BitMath/

I have a debounce method that shows me pin state history as 8 bits. Just by the number I can tell 8 reads over the last 4 millis as they were collected. I can tell if there was bouncing and when the pin becomes stable just by that number and not a series of if's.

GoForSmoke good points, but I fear all of that is going to be way over the OPs head at the moment.
First step for the OP should be just to use a SINGLE 3 position switch and get it working.
Also, most importantly, show us how it is wired.
Firstly a 3 position switch is not a “standard” bit of kit we are used to dealing with. Secondly if it is 3 position I’m not sure how that relates to 2 input pins?

So start by just connecting one switch and outputting the state of that switch to the serial monitor.
Once we, and the OP, knows how it works we can move onto more complex setups...

Why assume that the OP won’t understand bits?
Some people aren’t stuck on complicating what is not.

Yes it takes some study and practice to get good. I took notes on paper and kept them open at times, same as when taking class at school. Making notes forces words and helps memory. Reading them later brings more to memory.

Consider the time saved from writing and debugging loads of extra code due to not knowing most of C?

Anyone has to ask themselves what something can be worth, will it save time writing? Will it simplify modeling problems?

``````const byte swPin[] = { 4,5,6 };
const byte swVal[] = { 1 2, 4 }; // makes an array of 3 bytes with a value in each
byte   swBits;
byte   switch; // index switch 0,1, or 2
.....

swBits = 0;
for ( byte i = 0; i < 3; i++ )
{
if (  digitalRead( swPin[ i ] ) > 0 )
{
swBits += swVal[ i ];
}
}

switch( swBits )  // one way to quickly solve 3 T/F's for different combos
{
case 0 :  // no switches are ON
// code here
break;
case 1 :  // switch 0 is ON
// code here
break;
case 2 :  // switch 1 is ON
// code here
break;
case 4 :  // switch 2 is ON
// code here
break;
case 7 :  // all switches are ON
// code here
break;
default : // none of the above
// error/exception code here
}
.....
}
``````

In home i try show u what switch im using.

I Wired middle conector in GND and sides conector in pins... Making HIGH when get some position.

I found a way tô make this happen... Ill show How when i come house...

My question as cuz independent switch order when ALL If three get HIGH "something thing do"... But i wanna a sequence its like First switch activated are Second or thrid in the row

Ill show How i make It later

Nimb:
I Wired middle conector in GND and sides conector in pins… Making HIGH when get some position.

That wiring requires that your pins be declared as INPUT_PULLUP and they will read LOW when the switch is in that position, HIGH when it is in the middle/off position.

``````const byte switchPin[] = { 8, 9, 10, 11, 12, 13 };
const byte pinCount = sizeof(switchPin) / sizeof(switchPin);
int switch1, switch2, switch3;
enum { UP, MIDDLE, DOWN };

void setup() {
for( int i=0; i < pinCount; ++i ) {
pinMode(switchPin[i], INPUT_PULLUP);
}
}

void loop() {

if ( switch1 == UP and switch2 == DOWN and switch3 == UP ) {
// do something
} else {
// do something else
}
}

switch1 = MIDDLE;
if ( digitalRead(switchPin) == LOW ) switch1 = UP;
if ( digitalRead(switchPin) == LOW ) switch1 = DOWN;

switch2 = MIDDLE;
if ( digitalRead(switchPin) == LOW ) switch2 = UP;
if ( digitalRead(switchPin) == LOW ) switch2 = DOWN;

switch3 = MIDDLE;
if ( digitalRead(switchPin) == LOW ) switch3 = UP;
if ( digitalRead(switchPin) == LOW ) switch3 = DOWN;
}
``````

If you want something more sequential, like detecting the first switch is correct, then the second, etc. then you need to google “finite state machine” and implement something along those lines

Can a single physical switch be used for more than one number of the combination?

Why are not all of the switch pins connected to I/O pins since you're not switching power now, you're reading a switch.

How many pins connect electrically when the switch is in each position?

Is there more than one switch?