//PassBorderLine Task 6 Question 3

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

int LED{13};
int bA{2};
int bB{3};
bool state{false};

#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 4

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, 53, MAX_DEVICES);


//prots
void A();

void setup() {
pinMode(LED, OUTPUT);
P.begin();
//Serial.begin(115200);
attachInterrupt(digitalPinToInterrupt(bA), A, CHANGE);


  cli(); // stop interrupts

    // set timer 1 interrupt at 1Hz
  TCCR1A = 0; // set entire TCCR1A register to 0
  TCCR1B = 0; // ""    ""    ""  B    ""      ""
  TCNT1 = 0; // initialize counter1 value to 0;

  //set compare match register for 2Hz increments
  OCR1A = 15624/2; // = (16*10^6)/(2hz*1024)-1 (must be <65536)
  //turn on CTC mode
  TCCR1B |= (1<<WGM12);
  // Set CS12 and CS10 bits for 1024 prescaler
  TCCR1B |= (1<<CS12)|(1<<CS10);
  //enable timer compare interrupt
  TIMSK1 |=(1<<OCIE1A);

  sei(); //allow interrupts
}

void loop() {
  if (P.displayAnimate())
    P.displayText("I Love Swinburne", PA_CENTER, P.getSpeed(), P.getPause(), PA_SCROLL_RIGHT, PA_SCROLL_RIGHT);


}

///////////////////////////////////////

ISR(TIMER1_COMPA_vect)//timer1 interrupt 1HZ toggles pin 13
{
  
}

void A()
{
  static unsigned long lastMillis=0;
  unsigned long newMillis = millis();
  if(newMillis-lastMillis<200){}
  else
    {
    
    P.displayText("Vincent", PA_CENTER, P.getSpeed(), P.getPause(), PA_SCROLL_RIGHT, PA_SCROLL_RIGHT);
    //Serial.println("yes");
    lastMillis=newMillis;
    }
 
  
  
}