Preview:
int X[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
int Y[] = {0, 9, 10, 11, 12, 13, A0, A1, A2};

unsigned long patternStartTime = 0; // Variable to track pattern start time
const unsigned long patternDuration = 3000; // Pattern display duration in milliseconds
int currentPattern = 1; // Track the current pattern being displayed

void setup() {
  for (int i = 1; i < 9; i++) {
    pinMode(X[i], OUTPUT);
    pinMode(Y[i], OUTPUT);
    digitalWrite(X[i], HIGH);
    digitalWrite(Y[i], LOW);
  }
}

void loop() {
  switch (currentPattern) {
    case 1:
      displayHeartPattern();
      break;
    case 2:
      displaySecondPattern();
      break;
    case 3:
      displayThirdPattern();
      break;
  }

  if (millis() - patternStartTime >= patternDuration) {
    effacer(); // Clear the LED matrix
    delay(100); // Add a short delay for stability
    currentPattern = (currentPattern % 3) + 1; // Switch to the next pattern (1, 2, or 3)
    patternStartTime = millis(); // Reset pattern start time
  }
}

void displayHeartPattern() {
  byte heartPattern[8] = {
    B00000000,
    B00000000,
    B01100110,
    B01100110,
    B01100110,
    B10000001,
    B01000010,
    B00111100
  };

  displayPattern(heartPattern);
}

void displaySecondPattern() {
  byte secondPattern[8] = {
    B00000000,
    B00000000,
    B01100110,
    B01100110,
    B00000000,
    B01111110,
    B00000000,
    B00000000
  };

  displayPattern(secondPattern);
}

void displayThirdPattern() {
  byte thirdPattern[8] = {
    B00000000,
    B00000000,
    B01100110,
    B01100110,
    B01100110,
    B00111100,
    B01000010,
    B10000001
  };

  displayPattern(thirdPattern);
}

void displayPattern(byte pattern[8]) {
  for (int col = 0; col < 8; col++) {
    digitalWrite(Y[col + 1], LOW); // Activate column col+1

    for (int row = 0; row < 8; row++) {
      digitalWrite(X[row + 1], bitRead(pattern[col], row)); // Activate row row+1 if pattern is 1
    }

    delay(5); // Adjust
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter