// Include the Arduino Stepper.h library:
#include <Stepper.h> 
// Define number of steps per rotation:
const int stepsPerRevolution = 82; // Amount of step that takes the motor 25 minutes to do one rotation

// Wiring:
// Pin 8 to IN1 on the ULN2003 driver
// Pin 9 to IN2 on the ULN2003 driver
// Pin 10 to IN3 on the ULN2003 driver
// Pin 11 to IN4 on the ULN2003 driver
Stepper myStepper = Stepper(stepsPerRevolution, 6, 5, 4, 3); // Create stepper object called 'myStepper' with the pin order
extern volatile unsigned long timer0_millis; //Timer0 variable

void setup() {
  // Set the speed to 1 rpm:
  Serial.begin(9600);
  myStepper.setSpeed(1);
}

bool brk = false; //AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
long currentMillis, brkMillis = 0;

void loop() {
  //If we reach the 25 minute mark while not on a break
  if (currentMillis > 1500000 && !brk){
    
    //Reset variables
    currentMillis = 0; 
    brkMillis = 0; 
    
    brk = true; //Start the 5 minute break
    resetMillis(); //Reset the timer
  }

  if (brkMillis > 300000 && brk){

    //Reset variables
    brkMillis = 0;
    currentMillis = 0;
    
    brk = false; //Stop the break
    resetMillis(); //Reset the timer

    myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11); //Increase the steps of the motor so it spins faster
    myStepper.setSpeed(1); //Set the motor to 15 rpm (Max speed)
    
  }else if(brkMillis < 300000 && brk){
    animation();
  }
  
  myStepper.step(-stepsPerRevolution); //Spin the motor clockwise

  if(!brk){
  currentMillis = millis();
  Serial.print("Not Break ");
  Serial.println(currentMillis);
  }else{
    brkMillis = millis();
    Serial.print("Break ");
    Serial.println(brkMillis);
  }
}

void animation(){
  myStepper = Stepper(2048, 8, 10, 9, 11); //Increase the steps of the motor so it spins faster
  myStepper.setSpeed(15); //Set the motor to 15 rpm (Max speed)
  myStepper.step(-2048); //Turn the motor clockwise
}

//This function is to reset timer0 so it's easier to keep track of intervals.
void resetMillis(){
  noInterrupts ();
  timer0_millis = 0;
  interrupts ();
}
