8 x 32 led dot matrix md parola with button trigger

This is code using a 8 x 32 led dot matrix with a six string statement triggered by a button. When the button is pressed the statement start scrolling. After the first statement finishes the second one starts and so on. When finished with the sixth one it stops until button is pressed again.

#include "MD_Parola.h"
#include "MD_MAX72xx.h"
#include "SPI.h"

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
const byte CS_PIN = 12;
const byte DATA_PIN = 11;
const byte CLK_PIN = 13;
const byte button1 = 9;

MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
MD_Parola myDisplay1 = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

boolean message1;
boolean scroll;
int i;
int x;
int buttonCount = 0;

char *myStrings[] = { "Greetings From West Virginia USA", "Hope Your Having An Awesome Day", "Please Dont Litter",
                      "Let Me Hold A Dollar", "Be Kind To Animals And Children", "Hope This Helps - JohnathonJ" };

void setup() {
  Serial.begin(9600);
  pinMode(button1, INPUT_PULLUP);
  myDisplay.begin();
  myDisplay.setIntensity(0);
  myDisplay.setTextAlignment(PA_CENTER);
  myDisplay.print("Ready");
  delay(1000);
  myDisplay.displayClear();
  myDisplay1.begin();
  myDisplay1.setIntensity(0);
  message1 = false;
  scroll = false;
}

void loop() {
  if (digitalRead(button1) == LOW) {
    delay(250);
    buttonCount = 1;
    x = 0;
    i = 0;
  }
  if (buttonCount == 1) {
    message1 = true;
    buttonCount = 2;
  }
  if (message1 == true) {
    delay(500);
    Serial.println(myStrings[i]);
    Serial.print("i");
    Serial.println(i);
    Serial.print("x");
    Serial.println(x);
    myDisplay1.displayText(myStrings[i], PA_CENTER, 80, 0,
                           PA_SCROLL_LEFT, PA_SCROLL_LEFT);
    scroll = true;
    i++;
    x++;
    message1 = false;
  }

  if (scroll == true) {
    if (myDisplay1.displayAnimate()) {
      myDisplay1.displayReset();
      scroll = false;
      if (x <= 5) {
        buttonCount = 1;
      }
    }
  }
}

Now tell us the problem, or the post is just informative saying that it works ok.

Works Ok. I posted it under projects discussion and showcase. I'm always open to tips to improve my coding though.

To add more cycles to the string array.

#include "MD_Parola.h"
#include "MD_MAX72xx.h"
#include "SPI.h"

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
const byte CS_PIN = 12;
const byte DATA_PIN = 11;
const byte CLK_PIN = 13;
const byte button1 = 9;

MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
MD_Parola myDisplay1 = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

boolean message1;
boolean scroll;
int i;
int x;
int buttonCount = 0;

char *myStrings[] = { "Greetings From West Virginia USA", "Hope Your Having An Awesome Day", "Please Dont Litter",
                      "Let Me Hold A Dollar", "Be Kind To Animals And Children", "Hope This Helps - JohnathonJ" };

void setup() {
  Serial.begin(9600);
  pinMode(button1, INPUT_PULLUP);
  myDisplay.begin();
  myDisplay.setIntensity(0);
  myDisplay.setTextAlignment(PA_CENTER);
  myDisplay.print("Ready");
  delay(1000);
  myDisplay.displayClear();
  myDisplay1.begin();
  myDisplay1.setIntensity(0);
  message1 = false;
  scroll = false;
}

void loop() {
  if (digitalRead(button1) == LOW) {
    delay(250);
    buttonCount = 1;
    x = 0;
    i = 0;
  }
  if (buttonCount == 1) {
    message1 = true;
    buttonCount = 2;
  }
  if (message1 == true) {
    delay(500);
    Serial.println(myStrings[i]);
    Serial.print("i");
    Serial.println(i);
    Serial.print("x");
    Serial.println(x);
    myDisplay1.displayText(myStrings[i], PA_CENTER, 80, 0,
                           PA_SCROLL_LEFT, PA_SCROLL_LEFT);
    scroll = true;
    i++;
    x++;
    message1 = false;
    if (i == 6){//resets the string count
      i = 0;
    }
  }

  if (scroll == true) {
    if (myDisplay1.displayAnimate()) {
      myDisplay1.displayReset();
      scroll = false;
      if (x <= 29) {//increase this number by 6 to add more array cycles
        buttonCount = 1;//(x <= 29) the array will cycle 5 times
      }                 //remember the count starts at 0. 1 cycle would be (x <= 5)
    }
  }
}

To make it scroll non stop until button is pressed again

#include "MD_Parola.h"
#include "MD_MAX72xx.h"
#include "SPI.h"

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
const byte CS_PIN = 12;
const byte DATA_PIN = 11;
const byte CLK_PIN = 13;
const byte button1 = 9;

MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
MD_Parola myDisplay1 = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

boolean message1;
boolean scroll;
boolean lastButtonState = LOW;
boolean arrayStart;
boolean arrayGo;
boolean stop;
int i;

char *myStrings[] = {
  "Greetings From West Virginia USA",
  "Hope Your Having An Awesome Day",
  "Please Dont Litter",
  "Let Me Hold A Dollar",
  "Be Kind To Animals And Children",
  "Hope This Helps - JohnathonJ"
};
void setup() {
  Serial.begin(9600);
  pinMode(button1, INPUT_PULLUP);
  myDisplay.begin();
  myDisplay.setIntensity(0);
  myDisplay.setTextAlignment(PA_CENTER);
  myDisplay.print("Ready");
  delay(1000);
  myDisplay.displayClear();
  myDisplay1.begin();
  myDisplay1.setIntensity(0);
  message1 = false;
  scroll = false;
  stop = true;
}

void loop() {
  byte buttonState = digitalRead(button1);
  if (buttonState == LOW) {
    arrayStart = (arrayStart == true) ? false : true;
    arrayGo = true;
    stop = false;//adding this variable keeps the serial monitor from printing i7 repeatedly
    i = 0;             //while turned off which means the arduino board is not busy doing that
  }                      //when it's supposed to be in stop mode
  if ((arrayStart == false) && (stop == false)) {
    i = 7;//there are not seven strings stops an unwanted clich in led display
    myDisplay1.displayClear();
    stop = true;
  }
  if (arrayGo == true) {//buttonCount in previous codes can be changed to a boolean true/false
    message1 = true;
    arrayGo = false;
  }
  if (message1 == true) {
    delay(500);
    Serial.println(myStrings[i]);
    Serial.print("i");
    Serial.println(i);
    myDisplay1.displayText(myStrings[i], PA_CENTER, 80, 0,
                           PA_SCROLL_LEFT, PA_SCROLL_LEFT);
    scroll = true;
    i++;
    message1 = false;
    if (i == 6) {  //resets the string count
      i = 0;
    }
  }
  if (scroll == true) {
    if (myDisplay1.displayAnimate()) {
      myDisplay1.displayReset();
      scroll = false;
      if ((arrayStart == true) && (i <= 5)) {
        arrayGo = true;
      }
    }
  }
}

Had to change it to hardward spi

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.