How to display two individual scrolling messages on 8x32 MAX7219 ? [CLOSED post #23]

#include <MD_Parola.h>     // include MajicDesigns Parola library
#include <MD_MAX72xx.h>    // include MajicDesigns MAX72xx LED matrix library
#include <SPI.h>           // include Arduino SPI library

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW   // this line defines our dot matrix hardware type (FC-16)
#define MAX_DEVICES 4                       // define number of total cascaded modules

#define CS_PIN    10   // define CS (Chip Select) pin

MD_Parola display = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// attach the potentiometer
#define POTPIN   A5   // define speed control potentiometer output pin connection
// attach PIR sensors
#define PIR_SENSOR_1 3
#define PIR_SENSOR_2 2

uint8_t scrollSpeed = 150;    // set initial scroll speed, can be a value between 10 (max) and 150 (min)
textEffect_t scrollEffect  = PA_SCROLL_LEFT;  // scroll direction, right-to-left direction
textPosition_t scrollAlign = PA_LEFT;         // scroll align
uint16_t scrollPause = 2000;                  // scroll pause in milliseconds

// display messages
char message_1 [100] = {"Coming in!"};
char message_2 [100] = {"Coming out!"};

// Initialize variables to track PIR sensor readings
int pirSensor1Reading = 0;
int pirSensor2Reading = 0;

// No motion is detected at first, State are LOW
int pirSensor1State = LOW;
int pirSensor2State = LOW;

// Just joggling variables
int toggle_1 = 1;
int toggle_2 = 2;

// Initialize variables to keep track of the time
unsigned long previousMillis_1 = 0;
unsigned long currentMillis_1 = 0;
unsigned long previousMillis_2 = 0;
unsigned long currentMillis_2 = 0;

// setup function
void setup(void)
{
  Serial.begin(9600);

  // Set PIR sensor pins as input
  pinMode(PIR_SENSOR_1, INPUT);
  pinMode(PIR_SENSOR_2, INPUT);

  // initialize the dot matrix display
  display.begin();
  // set the intensity (brightness) of the display (choose a number between 0 and 15)
  display.setIntensity(5);
  // clear the whole display
  display.displayClear();

  // print text on the display
  //display.displayText(message, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
}

// main loop function
void loop(void)
{
  uint16_t an = analogRead(POTPIN);    // read analog data from potentiometer output

  int16_t speed = map(an, 0, 1023, 150, 10);  // map previous value between 150 & 10 (min & max speed)

  if ( speed != display.getSpeed() )   // check if speed changed
    display.setSpeed(speed);           // set new scrolling speed

  // Read PIR sensor 1
  pirSensor1Reading = digitalRead(PIR_SENSOR_1);

  // if PIR sensor 1 detects movement first
  if (pirSensor1Reading == HIGH && pirSensor1State == LOW) {
    Serial.println("PIR 1 detected movement first!");

    // then also read PIR sensor 2
    pirSensor2Reading = digitalRead(PIR_SENSOR_2);

    // if PIR sensor 2 also detects movement, but after PIR sensor 1
    if (pirSensor2Reading == HIGH && pirSensor2State == LOW) {

      Serial.println("PIR 2 detected movement second!");
      toggle_1 = ! toggle_1;
      pirSensor2State = HIGH;
      previousMillis_1 = millis();
    }
    if (pirSensor2Reading == LOW && pirSensor2State == HIGH)
    {
      pirSensor2State = LOW;
    }
  }
  if (pirSensor1Reading == LOW && pirSensor1State == HIGH)
  {
    pirSensor1State = LOW;
  }
  if (toggle_1 == 0)
  {
    Serial.println("Coming in!");
    currentMillis_1 = millis();
    if (currentMillis_1 - previousMillis_1 <= 10000)
    {
      Serial.println("Coming in!");
      if (display.displayAnimate()) {    // animate the display
        display.displayText(message_1, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
        display.displayReset();          // reset the current animation
      }
    }
    if (currentMillis_1 - previousMillis_1 > 10000)
    {
      Serial.println("Nothing coming in!");
      display.displayClear();
      toggle_1 = 1;
      pirSensor1Reading = LOW;
      pirSensor2Reading = LOW;
    }
  }
  // *******************************************************************************************************************************************
  // Read PIR sensor 2
  pirSensor2Reading = digitalRead(PIR_SENSOR_2);

  // if PIR sensor 2 detects movement first
  if (pirSensor2Reading == HIGH && pirSensor2State == LOW) {
    Serial.println("PIR 2 detected movement first!");

    // then also read PIR sensor 1
    pirSensor1Reading = digitalRead(PIR_SENSOR_1);

    // if PIR sensor 1 also detects movement, but after PIR sensor 2
    if (pirSensor1Reading == HIGH && pirSensor1State == LOW) {

      Serial.println("PIR 1 detected movement second!");
      toggle_2 = ! toggle_2;
      pirSensor1State = HIGH;
      previousMillis_2 = millis();
    }
    if (pirSensor1Reading == LOW && pirSensor1State == HIGH)
    {
      pirSensor1State = LOW;
    }
  }
  if (pirSensor2Reading == LOW && pirSensor2State == HIGH)
  {
    pirSensor2State = LOW;
  }
  if (toggle_2 == 0)
  {
    Serial.println("Coming out!");
    currentMillis_2 = millis();
    if (currentMillis_2 - previousMillis_2 <= 10000)
    {
      Serial.println("Coming out!");
      if (display.displayAnimate()) {    // animate the display
        display.displayText(message_2, scrollAlign, scrollSpeed, scrollPause, scrollEffect, scrollEffect);
        display.displayReset();          // reset the current animation
      }

    }
    if (currentMillis_2 - previousMillis_2 > 10000)
    {
      Serial.println("Nothing coming out!");
      display.displayClear();
      toggle_2 = 1;
      pirSensor1Reading = LOW;
      pirSensor2Reading = LOW;
    }
  }

} // end of code.