4x4 Matrix Code

I have a 4x4 set of buttons and I am attempting to output a two-dimensional array of 0's. When I press a button in that 4x4 set of buttons I want a specific 0 to change to a 1 when a button is pressed. This code is not outputting anything, please help.

sketch_jun11a.ino (701 Bytes)

I have a 4x4 set of buttons

How are they wired? Do you have a diode associated with each button? If not you will only be able to press one button at any one time and have it work.
Please post a schematic.

Can’t comment on the code because I am in a mobile device. If you read the how to use this forum sticky post it will tell you only to do this if the code is too long to post between the code tags you get when you press the icon on the top right hand corner that look like a </>

#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = {
  {'A', 'B', 'C', 'D'},
  {'E', 'F', 'G', 'H'},
  {'I', 'J', 'K', 'L'},
  {'M', 'N', 'O', 'P'}};

byte rowPins[ROWS] = {D4, D3, D2, D1};
byte colPins[COLS] = {D8, D7, D6, D5};

Keypad myKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

int buttons[4][4] = {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}};

void setup(){
  Serial.begin(115200);
  
}

void loop(){
  char keyPressed = myKeypad.getKey();
  int buttons[4][4] = {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}};
  //buttons[ROWS][COLS] = 1;

if (keyPressed != NULL) {
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      Serial.print(buttons[i][j]);
    }
    Serial.println("");
  }
}
}

Each column is wired with diodes to each button and each row is wired normally.

The diodes need to be between row and column.

BenJR391:
Each column is wired with diodes to each button and each row is wired normally.

Schematic needed, so we can see what your version of "normal" is and how those diodes are exactly etc.

BenJR391:
This code is not outputting anything.

That code will not even compile, so you can not be running it.

In these two lines:-

byte rowPins[ROWS] = {D4, D3, D2, D1};
byte colPins[COLS] = {D8, D7, D6, D5};

You use variables that have not been defined. All those variables have not been defined.

When posting code please post the code that you use, you clearly have not used what you posted, unless it won't even compile and upload to the Arduino. In which case you should have said this.

Grumpy_Mike:
That code will not even compile, so you can not be running it.

In these two lines:-

byte rowPins[ROWS] = {D4, D3, D2, D1};

byte colPins[COLS] = {D8, D7, D6, D5};




You use variables that have not been defined. All those variables have not been defined.

They are defined on some ESP8266 boards, maybe others as well.