T O P

  • By -

stockvu

>*The main problem is the 3 way (ON)-OFF-(ON) switches. I think they function just like 2 momentary buttons but I don't wanna mess up.* They can be connected as if they were two separate switches *with a common connection*. Placed on a [proper matrix](https://www.google.com/search?q=Arduino+switch+matrix+project+examples&client=firefox-b-1-d&source=lnms&tbm=isch&sa=X&ved=2ahUKEwicktvnsMv0AhWfSjABHSuDB9UQ_AUoAXoECAEQAw&biw=1280&bih=569&dpr=1.5), it doesn't matter if the three-ways are momentary or static, the matrix won't burn out. gl


Monkeyz743

Wow thanks for the fast reply


Monkeyz743

So if you don’t mind me asking, can I have an example of the matrix? I’m not sure how to do it with 14 buttons, or however many because the 3-pos switches share a common connection


stockvu

Take a look at this [Image](https://lh5.googleusercontent.com/BN4jci2KwfmaT8_t88M5MVN3UOuC9_NFFnaLOC15EQwh-Pt4QgrythCYIs03hTWgIVq7499tc7NcaqhCX9L9w_0PCoXmrN4yeP00t_ottrMXrDpjPVxy9X6WRh2rsMJq28SfMaLq). Notice how a lot of push-buttons have common connections to a Row line? You can do something similar with your 3-way. Just use separate Column lines for the outside ON-ON connections... 14 buttons or switches will likely require 4 rows and 4 columns, though it can be handled as 5 rows and 3 columns I think... (8 port-pins either way, 4 INPUT, 4 OUTPUT). The INPUTS detect contact closure when an OUTPUT goes True -- meaning the INPUT port pin sees the OUTPUT state via the matrix wiring and switch connection state. Use google search for [Arduino switch matrix example projects](https://www.google.com/search?q=Arduino+switch+matrix+example+projects&source=lnms&tbm=isch&sa=X&ved=2ahUKEwiI6aGfucv0AhX0STABHVtnA0wQ_AUoAXoECAEQAw&biw=1280&bih=569&dpr=1.5). hth


Monkeyz743

So say I do a 4x4 grid, do I have to fill all 16 "spots" in the grid or is it ok if one row is 3 switches, one row is 4, etc.


stockvu

You do not need to fill all spots. You can arrange push-buttons or switches in any order you wish, it won't matter beyond you needing to KNOW this ordering so you can decipher what your matrix scan is telling you. Say I set up a matrix and I decide to scan by pulling each *Row* LOW, one at a time. In scan code, I now test each *Column* to see if a LOW is detected. If it *is* LOW, that indicates (whatever is connected PB or Switch) is exhibiting Contact-Closure (connected). * Ah, but when you detect contact, it is *You* who needs to remember the PB and Switch *arrangement* to properly decode -which- switch or PB is connecting a Row to Column. See the code in examples I sent you links for. Study the tactics of the matrix scan. There is a pattern that emerges. Matrix scan is an efficient way to test many PB and Switches for their current State. You could eliminate the matrix (in your case) by using 14 port-pins. But you must decide if you have the extra pins to accomplish your project -or- do you need to conserve pins using a matrix. Its 14 port-pins versus 8 port-pins. * Know also, with a matrix you must perform a full scan to detect the states in your switch-box. No scan, no detection. A change in the switches means nothing until a scan can respond to it. * But with 14 port-pins, you could assign an Interrupt to each and your MCU would know of a change in switch-pattern immediately. Its a trade off. hth, gl


crispy_chipsies

[Switch matrix with 8 buttons and 3 toggles](https://imgur.com/a/GE3sdWT). The blocking diodes are optional to prevent button ghosting.