Debouncing arrays of multiplexer buttons

Hello

I am trying debounce an array of buttons. I am using a multiplexer. I have tested the multiplexer using the cose from this tutorial ( Multiplexer Breakout Hookup Guide - learn.sparkfun.com ) and it works fine.
Then I made a few changes to the code to debounce one single button from an array of buttons (MuxButton) and that works fine. Only when I try and do the same thing for the whole array I cannot get a print out to see if it is working. I cannot figure out what I am getting wrong.
I am going to paste below the working code (the one testing only MuxButton[0] and the non working code. they are practically identical with the only difference that in the non working code I am using an array of lastDebounceTime.

///////////////////////  WORKING CODE MUX ///////////////////////

const int selectPins[3] = {0, 1, 2};                       // S0~2, S1~3, S2~4
const int zInput = 3;                                      // Connect common (Z) to arduino pin
boolean MuxButton [8] = {HIGH};                            // buttons on mux
boolean MuxButtonPState = HIGH;                            // previous state of mux button
unsigned long lastDebounceTime = 0;                        // the last time the output pin was toggled
unsigned long debounceDelay = 20;                          // the debounce time; increase if the output flickers
int count = 0;

void setup() {
  Serial.begin(9600);
  for (int i = 0; i < 3; i++) {                             // Set up the select pins as outputs:
    pinMode(selectPins[i], OUTPUT);
    digitalWrite(selectPins[i], HIGH);
  }
  pinMode(zInput, INPUT_PULLUP);
}

void loop() {
  MuxRead();

  if (MuxButton[0] != MuxButtonPState) {
    if  ((millis() - lastDebounceTime) > debounceDelay) {
      lastDebounceTime = millis();
      if (MuxButton[0] == LOW) {
        count = count + 1;
        Serial.println(count);
      }
      MuxButtonPState = MuxButton[0];
    }
  }
}

void MuxRead() {
  for (byte pin = 0; pin <= 7; pin++) {                     // Loop through all eight pins.
    selectMuxPin(pin);                                      // Select one at a time
    int inputValue = digitalRead(zInput);                   // read Z
    if (pin < 5) {
      inputValue = !inputValue;
    }
    MuxButton[pin] = inputValue;
  }
}

void selectMuxPin(byte pin) {                               // The selectMuxPin function sets the S0, S1, and S2 pins
  for (int i = 0; i < 3; i++) {                             // so that the select all 8 pins in succession
    if (pin & (1 << i))
      digitalWrite(selectPins[i], HIGH);
    else
      digitalWrite(selectPins[i], LOW);
  }
}
/////////////////////// NON WORKING CODE MUX ///////////////////////


const int selectPins[3] = {0, 1, 2};                       // S0~2, S1~3, S2~4
const int zInput = 3;                                      // Connect common (Z) to arduino pin
const int MaxPinNumber = 8;                                // number of buttons attached to multiplexer
boolean MuxButton [MaxPinNumber] = {HIGH};                 // buttons on mux
boolean MuxButtonPState [MaxPinNumber] = {HIGH};           // mux channel previous state
unsigned long lastDebounceTime [MaxPinNumber] = {0};       // the last time the output pin was toggled
unsigned long debounceDelay = 5;                           // the debounce time; increase if the output flickers
int count [MaxPinNumber] = {0};

void setup() {
  Serial.begin(9600);
  for (int i = 0; i < 3; i++) {                             // Set up the select pins as outputs:
    pinMode(selectPins[i], OUTPUT);
    digitalWrite(selectPins[i], HIGH);
  }
  pinMode(zInput, INPUT_PULLUP);                            // Set up Z as an input
}

void loop() {
  void MuxRead();
  for (int i = 0; i < MaxPinNumber; i++) {
    if (MuxButton[i] != MuxButtonPState[i]) {
      if  ((millis() - lastDebounceTime[i]) > debounceDelay) {
        lastDebounceTime[i] = millis();
        if (MuxButton[i] == LOW) {
          count[i] = count[i] + 1;
          Serial.print(count[i]);
          Serial.print("\t");
        }
        MuxButtonPState[i] = MuxButton[i];
      }
    }
  }
  Serial.println();
}

void MuxRead() {
  for (byte pin = 0; pin <= 7; pin++) {                     // Loop through all eight pins.
    selectMuxPin(pin);                                      // Select one at a time
    int inputValue = digitalRead(zInput);                   // read Z
    if (pin < 5) {
      inputValue = !inputValue;
    }
    MuxButton[pin] = inputValue;
  }
}

void selectMuxPin(byte pin) {                               // The selectMuxPin function sets the S0, S1, and S2 pins
  for (int i = 0; i < 3; i++) {                             // so that the select all 8 pins in succession
    if (pin & (1 << i))
      digitalWrite(selectPins[i], HIGH);
    else
      digitalWrite(selectPins[i], LOW);
  }
}

What pops into my eyes is a small mishab:

void loop() {
  void MuxRead(); //There should be no "void" here..
  ...
}

Thank you very much. That sorted the problem. :slight_smile: