Led Matrix boards how to combine sketches?

Good day,

After reading and reading i just did not found a solution to my problem so i hope you can help me out.

For a project i'm trying to use 2 8x8 led matrix boards with a different animation per board. The animations are more then 20 seconds long (i will post only a part of it because its useless to post it all) so its a lot of code! (For the animation code i use this https://xantorohara.github.io site)

I'm trying to use different pins for each matrix board because for me its much easier to write that way

Both sketches work! But i don't know how to combine them so that the Arduino can play them both at the same time

first sketch

#include <LedControl.h>

const int DIN_PIN = 7;
const int CS_PIN = 9;
const int CLK_PIN = 8;

const uint64_t IMAGES[] PROGMEM = {
 
  0x00009f9f9f9f0000,
  0x007e9f9f9f9f7e00,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,
  0x3c7e9f9f9f9f7e3c,

};
const int IMAGES_LEN = sizeof(IMAGES)/8;

LedControl display = LedControl(DIN_PIN, CLK_PIN, CS_PIN);

void setup() {
  display.clearDisplay(0);
  display.shutdown(0, false);
  display.setIntensity(0, 10);
}

void displayImage(uint64_t image) {
  for (int i = 0; i < 8; i++) {
    byte row = (image >> i * 8) & 0xFF;
    for (int j = 0; j < 8; j++) {
      display.setLed(0, i, j, bitRead(row, j));
    }
  }
}

int i = 0;

void loop() {
  uint64_t image;
  memcpy_P(&image, &IMAGES[i], 8);

  displayImage(image);
  if (++i >= IMAGES_LEN ) {
    i = 0;
  }
  delay(70);
}

second sketch

#include <LedControl.h>

const int DIN_PIN = 12;
const int CS_PIN = 10;
const int CLK_PIN = 11;

const uint64_t IMAGES[] PROGMEM = {
 
  0x3c7ee7e7e7e77e3c,
  0x3c7ee7e7e7e77e3c,
  0x3c7ee7e7e7e77e3c,
  0x3c7ee7e7e7e77e3c,
  0x3c7ee7e7e7e77e3c,
  0x3c7ee7e7e7e77e3c,
  0x3c7ee7e7e7e77e3c,
  0x3c7ee7e7e7e77e3c,
  0x007ee7e7e7e77e00,
  0x0000e7e7e7e70000,
  0x000000e7e7000000,
  0x0000000000000000,
  0x000000e7e7000000,
  0x0000e7e7e7e70000,
  0x007ee7e7e7e77e00,
  0x3c7ee7e7e7e77e3c,

};
const int IMAGES_LEN = sizeof(IMAGES)/8;

LedControl display = LedControl(DIN_PIN, CLK_PIN, CS_PIN);

void setup() {
  display.clearDisplay(0);
  display.shutdown(0, false);
  display.setIntensity(0, 10);
}

void displayImage(uint64_t image) {
  for (int i = 0; i < 8; i++) {
    byte row = (image >> i * 8) & 0xFF;
    for (int j = 0; j < 8; j++) {
      display.setLed(0, i, j, bitRead(row, j));
    }
  }
}

int i = 0;

void loop() {
  uint64_t image;
  memcpy_P(&image, &IMAGES[i], 8);

  displayImage(image);
  if (++i >= IMAGES_LEN ) {
    i = 0;
  }
  delay(70);
}

If you connect two matrices to different pins, your combined sketch would need two instances of the LedControl class, wouldn't it?

If you look at loop() in both sketches, you read a value from PROGMEM and display it. Reading two values, from different locations, and storing them in separate variables, doesn't seem even remotely difficult.

You'd need to change the displayImage() function to know which instance to display the value on. That's pretty easy.

Make some attempt to combine the two sketches, and show us that attempt, and explain what the issues are, if there are any.