Button Matrix Help

I’m trying to wire a button matrix for a PC Controller to increase the number of buttons from 12 to 16.
The tutorial I started said to use digital pins for the columns, and analog pins for the rows, do I absolutely need to use analog pins, or can I use all digital pins? I need the analogs open for 2 joysticks.

I’m using an Arduino Pro Micro (4 analog pins, 12 digital pins), I want to make a 4x4 matrix

That depends on the circuit and how keypresses are detected. Normally digital pins are used for both

Please post a link to the tutorial for more advice in context

Excellent, I havent built anything yet so ill see if using just digital works

Heres the video I’m watching:

The project that you link to uses the Keypad library so will work fine with digital pins for the keypad rows and columns

Sounds good, what if i just use the joy stick library, that also has button push functions

Which loystick library ?
Which pins does its examples use ?

Joystick Library by MHeironimus, I cant find Matrix example

Looking at the JoystickButton example from the library it does not use a button matrix, rather the sketch just polls 4 digital pins to test their input state

  for (int index = 0; index < 4; index++)
  {
    int currentButtonState = !digitalRead(index + pinToButtonMap);
    if (currentButtonState != lastButtonState[index])
    {
      Joystick.setButton(index, currentButtonState);
      lastButtonState[index] = currentButtonState;
    }
  }

The library setButton() function sets the state of a pin number passed to it

void Joystick_::setButton(uint8_t button, uint8_t value)
{
	if (value == 0)
	{
		releaseButton(button);
	}
	else
	{
		pressButton(button);
	}
}

Does that serve as a matrix? I’m trying to have more buttons than there are digital pins

No. It uses one pin per button

Ok Ill just make a matrix then
Thanks

Good News! It DOES work with only digital pins

Of course. It only uses “analog” pins because in the ATmega processors they in fact are digital pins which just happen to have additional analog capability if - and only if - it is required.

Ok great

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.