// Include the required Arduino libraries:
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

// Define hardware type, size, and output pins:
// #define HARDWARE_TYPE MD_MAX72XX::FC16_HW   // For real project
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW   // For Wokwi

#define MAX_DEVICES 4
#define CS_PIN 3

// Create a new instance of the MD_Parola class with hardware SPI connection:
// MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

// Setup for software SPI:
#define DATA_PIN 4
#define CLK_PIN 5
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

const int pinButton = 2;
int lastButtonState = HIGH;  // HIGH is button not pressed
int index = 0;
#define NUM_MESSAGES 2
char *pMessages[NUM_MESSAGES] =
{
  "Hello World",
  "Happy Birthday",
};

void setup() {
  Serial.begin( 9600);
  Serial.println( "The sketch has started");
  pinMode( pinButton, INPUT_PULLUP);

  // Intialize the object:
  myDisplay.begin();
  // Set the intensity (brightness) of the display (0-15):
  myDisplay.setIntensity(0);
  // Clear the display:
  myDisplay.displayClear();
  myDisplay.displayText("TEST MESSAGE - It works. !! @@ $$", PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
}

void loop() {
  
  int buttonState = digitalRead( pinButton);
  if( buttonState != lastButtonState)
  {
    if( buttonState == HIGH)
    {
      index++;
      if( index >= NUM_MESSAGES)
      {
        index = 0;
      }
      Serial.println( pMessages[index]);
      myDisplay.displayClear();
      myDisplay.displayText( pMessages[index], PA_CENTER, 100, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
    }
    lastButtonState = buttonState;
  }

  if (myDisplay.displayAnimate()) {
    myDisplay.displayReset();
  }
}