Besoin d'un petit coup de main pour la fin d'une programmation

Allo, j'aimerais avoir un coup de main pour savoir comment je peux ajouter une fin à un jeu de grille à remplir sur un matrix 8x8. Je voudrais releaser un relais quand la grille est toute allumée et inscrire un message sur mon matrix. des pistes svp?

// basé sur le code original de Krishna Lalith
#include <Keypad.h>                                                           //librairies
#include <LedControl.h>

const byte ROWS = 4; //quatre rangees         ;                                    //rangees
const byte COLS = 4; //quatre colonnes                                         //colonnes
char keys[ROWS][COLS] = {                                                     //deux dimensions
  {'M', 'N', 'O', 'P'},
  {'I', 'J', 'K', 'L'},
  {'E', 'F', 'G', 'H'},
  {'A', 'B', 'C', 'D'}
};
byte rowPins[ROWS] = {2, 3, 4, 5};                                            //connexions arduino digit rangees
byte colPins[COLS] = {6, 7, 8, 9};                                            //connexions arduino digit colonnes

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );     //instance pour keypad


int DIN = 12;
int CS =  11;
int CLK = 10;
LedControl lc = LedControl(DIN, CLK, CS, 0);

int FIVER[4][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
int r, c, i, j;
int flag = 1;


void setup() {
  Serial.begin(9600);
  lc.shutdown(0, false);      // Debut
  lc.setIntensity(0, 1);      // intensite lumineuse
  lc.clearDisplay(0);         // eteindre
  randomSeed(analogRead(0));

}



void loop() {
  if (flag == 1) {
    for (i = 0; i < 4; i++) {
      for (j = 0; j < 4; j++) {
        FIVER[i][j] = random(0, 2);
      }
    }

    flag = 0;

    for (i = 0; i < 4; i++) {
      for (j = 0; j < 4; j++) {
        if (FIVER[i][j] == 1) {
          lc.setLed(0, 2 * i, 2 * j , true);
          lc.setLed(0, 2 * i + 1, 2 * j , true);
          lc.setLed(0, 2 * i, 2 * j + 1 , true);
          lc.setLed(0, 2 * i + 1, 2 * j + 1 , true);
        }
        if (FIVER[i][j] == 0) {
          lc.setLed(0, 2 * i, 2 * j , false);
          lc.setLed(0, 2 * i + 1, 2 * j , false);
          lc.setLed(0, 2 * i, 2 * j + 1 , false);
          lc.setLed(0, 2 * i + 1, 2 * j + 1 , false);
        }
      }
    }
  }

  char key = keypad.getKey();
  //definir les contenus

  if (key == 'A') {
    r = 0;
    c = 0;
  }
  if (key == 'B') {
    r = 0;
    c = 1;
  }
  if (key == 'C') {
    r = 0;
    c = 2;
  }
  if (key == 'D') {
    r = 0;
    c = 3;
  }
  if (key == 'E') {
    r = 1;
    c = 0;
  }
  if (key == 'F') {
    r = 1;
    c = 1;
  }
  if (key == 'G') {
    r = 1;
    c = 2;
  }
  if (key == 'H') {
    r = 1;
    c = 3;
  }
  if (key == 'I') {
    r = 2;
    c = 0;
  }
  if (key == 'J') {
    r = 2;
    c = 1;
  }
  if (key == 'K') {
    r = 2;
    c = 2;
  }
  if (key == 'L') {
    r = 2;
    c = 3;
  }
  if (key == 'M') {
    r = 3;
    c = 0;
  }
  if (key == 'N') {
    r = 3;
    c = 1;
  }
  if (key == 'O') {
    r = 3;
    c = 2;
  }
  if (key == 'P') {
    r = 3;
    c = 3;
  }

  if (key) {
    for (i = 0; i < 4; i++) {
      FIVER[i][c] = 1 - FIVER[i][c];
    }
    for (i = 0; i < 4; i++) {
      FIVER[r][i] = 1 - FIVER[r][i];
    }
    FIVER[r][c] = 1 - FIVER[r][c];

    for (i = 0; i < 4; i++) {
      for (j = 0; j < 4; j++) {
        if (FIVER[i][j] == 1) {
          lc.setLed(0, 2 * i, 2 * j , true);
          lc.setLed(0, 2 * i + 1, 2 * j , true);
          lc.setLed(0, 2 * i, 2 * j + 1 , true);
          lc.setLed(0, 2 * i + 1, 2 * j + 1 , true);
          
        }
        if (FIVER[i][j] == 0) {
          lc.setLed(0, 2 * i, 2 * j , false);
          lc.setLed(0, 2 * i + 1, 2 * j , false);
          lc.setLed(0, 2 * i, 2 * j + 1 , false);
          lc.setLed(0, 2 * i + 1, 2 * j + 1 , false);
          
        }
      }
    }
  }
}

écrivez une fonction qui teste quand la grille est toute allumée et appelez là à chaque fois que vous allumez une nouvelle LED. si elle retourne "vrai" alors faites votre truc sur le relai et l'écran, sinon continuez