Counter button jump numbers on multiple matrix displays

Hello all, i am new at arduino and i have the following problem. I have create a counter playing on three matrix screens. Each screen has one arduino mega. I did that because if i use one Arduino i need bigger screen cables and they lose their signal. I have 2 1632 and 6432 matrix. My problem is that when i hit the button (arcade button) sometimes it jump numbers, for example from 123 to 124. So not all the screens diaplay the same number. It happens not repeatedly but for example from 100 to 200 it will have 2-4 numbers difference between the screens especially from 1632 to 6432. Any solutions? It is matter of code or cables- connections;

Note: i use the same code for each arduino mega.

Thanks

And this is my code.

#include <EEPROM.h>
#include <RGBmatrixPanel.h>
#include <Keypad.h>

#define CLK 11 // USE THIS ON ADAFRUIT METRO M0, etc.
#define OE 9
#define LAT 10
#define A A0
#define B A1
#define C A2
#define D A3

RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 64);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'D', 'Z', '0', 'X'},
{'C', '9', '8', '7'},
{'B', '6', '5', '4'},
{'A', '3', '2', '1'}
};
byte rowPins[ROWS] = {47, 49, 51, 53}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {39, 41, 43, 45}; //connect to the column pinouts of the keypad

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

int BUTTON = 12;
long b = 0;
int i = 0;
char count[6];

byte j;
char arr[4];

void setup() {
Serial.begin(9600);
pinMode(BUTTON, INPUT);
Serial.println(EEPROMReadlong(0));
b = EEPROMReadlong(0);
initscreen();
}

void loop() {
char key = customKeypad.getKey();
if (key == 'D') {
inputkeypad();
}

if (digitalRead(BUTTON) == LOW) {
long address = 0;
b++;
checkifbmax();
matrix.fillScreen(0);
matrix.setCursor(3, 9); // start at top left, with one pixel of spacing
matrix.setTextSize(2); // size 1 == 8 pixels high
matrix.print(b / 10000U);
matrix.print(b / 1000U % 10);
matrix.print(b / 100U % 10);
matrix.print(b / 10U % 10);
matrix.print(b / 1U % 10);
delay(200);
EEPROMWritelong(address, b);
address += 4;
}

}

void inputkeypad() {
long address = 0;
matrix.fillScreen(0);
matrix.setCursor(3, 9);
matrix.setTextSize(2);
j = 0;
while (j < 5) {
char key = customKeypad.getKey();
if (key) {
arr[j++] = key;
matrix.print(key);
Serial.print(key);
}
}
Serial.println( );
for (byte i = 0; i <= sizeof(arr); i++) {
Serial.print(arr*);*

  • }*
  • b = atol(arr);*
  • checkifbmax();*
  • Serial.println(b);*
  • matrix.fillScreen(0);*
  • matrix.setCursor(3, 9); // start at top left, with one pixel of spacing*
  • matrix.setTextSize(2);*
  • matrix.print(arr[0]);*
  • matrix.print(arr[1]);*
  • matrix.print(arr[2]);*
  • matrix.print(arr[3]);*
  • matrix.print(arr[4]);*
  • EEPROMWritelong(address, b);*
  • address += 4;*
    }
    void checkifbmax() {
  • if (b > 99999) {*
  • b = 0;*
  • }*
    }
    void initscreen() {
  • matrix.begin();*
  • matrix.setCursor(3, 9);*
  • matrix.setTextSize(2);*
  • matrix.setTextColor(matrix.Color333(7, 0, 0));*
  • matrix.print(b / 10000U);*
  • matrix.print(b / 1000U % 10);*
  • matrix.print(b / 100U % 10);*
  • matrix.print(b / 10U % 10);*
  • matrix.print(b / 1U % 10);*
    }
    void EEPROMWritelong(int address, long value)
    {
  • byte four = (value & 0xFF);*
  • byte three = ((value >> 8) & 0xFF);*
  • byte two = ((value >> 16) & 0xFF);*
  • byte one = ((value >> 24) & 0xFF);*
  • //Write the 4 bytes into the eeprom memory.*
  • EEPROM.write(address, four);*
  • EEPROM.write(address + 1, three);*
  • EEPROM.write(address + 2, two);*
  • EEPROM.write(address + 3, one);*
    }
    long EEPROMReadlong(long address)
    {
  • //Read the 4 bytes from the eeprom memory.*
  • long four = EEPROM.read(address);*
  • long three = EEPROM.read(address + 1);*
  • long two = EEPROM.read(address + 2);*
  • long one = EEPROM.read(address + 3);*
  • return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);*
    }

Attach the wiring diagram. I already think of usual faults.

I am not in my lab now but i will scetch one with pencil. Give me 10 min. Thanks in advance.

This is the diagram (attached)

Now it has attached photos!

Now people can see the photos

Thank you Delta_g & railroader any potential solution is welcome.

Any help pls;

please learn how to use code tags, as well as inserting photos!

Your problem is not checking the change of state for the button.
You need to tes if has been pressed or released, not just open or closed.

Your EEPROM functions can be replaced by a single call to eeprom.put() and eeprom.get(). !

Panoskoum:
Any help pls;

To get better help read the “How to use this forum” post and come back and fix your OP so the code is more readable.

If you want to be successful in this game then reading the instructions first is a habit you should build.