#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 11
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
#define inputPin 2 // which input pin is connected to button *
const int debounceDelay = 10; // milliseconds to wait until button input stable *
#define LED 8 // The pin the button-LED is connected to
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
void setup() {
P.begin();
// put your setup code here, to run once
Serial.begin(9600); // initializes serial monitor for troubleshooting and learning
pinMode(inputPin, INPUT); // make button pin mode input *
digitalWrite(inputPin, HIGH); //turn on internal pull-up on pin and set resting state to HIGH *
attachInterrupt(digitalPinToInterrupt(inputPin), buttonPushed, LOW); // assign interrupt to button, procedure to be run and set state to LOW when pushed *
pinMode(LED, OUTPUT); // Declare the button-LED as an output
}
void loop() {
if (P.displayAnimate()){
P.displayText("I love Swinburne", PA_CENTER, P.getSpeed(), P.getPause(), PA_NO_EFFECT);
}
delay(50);// pause to read serial monitor output
}
void buttonPushed() { // detect and debounce button push using assigned interrupt *
if (debounce(inputPin)) { // calls debounce procedure *
P.displayText("James Prendergast", PA_CENTER, P.getSpeed(), P.getPause(), PA_SCROLL_RIGHT);
digitalWrite(LED, LOW); // Turn the button-LED back off
}
}
// debounce returns true if the switch in the given pin is closed and stable
boolean debounce(int pin)
{
boolean state;
boolean previousState;
previousState = digitalRead(pin); // store switch state
for (int counter = 0; counter < debounceDelay; counter++)
{
delay(1); // wait for 1 millisecond
state = digitalRead(pin); // read the pin
if ( state != previousState)
{
counter = 0; // reset the counter if the state changes
previousState = state; // and save the current state
}
}
// here when the switch state has been stable longer than the debounce period
return state;
}