MHeironimus / ArduinoJoystickLibrary

An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
GNU Lesser General Public License v3.0
2.07k stars 403 forks source link

Double input when using multiple toggle switches #169

Open IanRawz opened 3 years ago

IanRawz commented 3 years ago

Description of Issue

I would like to use 4 toggle switches on my buttonbox, but I just can't get it to work. Whenever I switch the toggle switches on, i'm getting double (or more) inputs from the other buttons. Is there a way to fix this? Thanks.

Technical Details

Sketch File that Reproduces Issue

Used the amstudio sketch & guide from youtube https://www.youtube.com/watch?v=Z7Sc4MJ8RPM Sketch: https://bit.ly/3152ALk

Wiring Details

This is my button matrix: (T = toggle, B = button)

A3: T--B--B--B--B
    |  |  |  |  |
A2: B--T--B--B--B
    |  |  |  |  |
A1: B--B--T--B--B
    |  |  |  |  |
15: B--B--B--T
    14 16 10 9  8
Reisen-Wandern-Tauchen commented 3 years ago

It seems that you are facing one of the basic issues with button matrices... it's called "ghosting". You can prevent this by using a diode on each output pin of your switches (to prevent power flowing in the wrong direction) in combination with multiplexed reading (only swith 1 input pin HIGH at a time, then reading all the outputs, then swithing all inputs LOW and switch the next one input pin high and repeat the whole procedure) This article may help: https://www.baldengineer.com/arduino-keyboard-matrix-tutorial.html