Daily Time Lapse camera panner for stepper motor (Lockdown project)

Greetings,

I have managed to create myself a waterproof panning camera mount from some scrap metal and a bearing from a fidget spinner. Photos attached.

My plan is to mount it on my balcony and have it rotate slowly throughout the day and have a gopro record sunrise and sunset in time lapse for the duration of lockdown...

I have been successful at defining the angle and time to perform the rotation from zero to defined angle but I want to ensure that the camera is always facing east(ish) for sunrise every morning and facing west(ish) for sunset. As the day length changes by a few minutes each day (gets shorter) I dont want to have the panning begin at the same each time day but rather a defined time about 30min beofre sunrise as outlined in the table here: Sunrise and sunset times Dunedin, New Zealand

So in anticipation i have included a DS1307 Real time clock but need some help implementing code

my thinking is that i need to store the sunrise times for the next X days into an array and compare the times to begin each days pan. the length of the pan would be defined in a second array.

i am not very good with arrays and using the RTC to make comparisons so i would really appreciate any help to get me started.

Below is the code that I have created so far and is working to move the stepper:
it allows modification of the time and angle and returns to home (limit switch) after each pan sequence.

any ideas and help to get me moving would be really appreciated!

Thanks in advance.

p.s. code will be in the next comment..

Here is the code:

#include "RTClib.h"

RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};


const int HomeSwitch = 2;
const int ledPin =  3; 
const int CW = 1;     //direction of rotation  
const int CCW = 0;

int Pin1 = 12; 
int Pin2 = 11; 
int Pin3 = 10; 
int Pin4 = 9; 
int _step = 0; 
//boolean dir = false;// false=clockwise, true=counter clockwise
int count=0;
int RotationSpeed = 80;
int HomeSpeed = 98;
int ledState = LOW;

/////////////////////////////
// enter rotation angle here
const float StepsPerRotation = 4076;
float DegreeForRotation = 90;              // enter desired rotation degrees
float StepsforSelectedRotation; 

/////////////////////////////
// enter time period here
float HoursToRotate = 0.0083; 
float SecondsToRotate; 
float MilisecondToRotate;

float DelayBetweenStep;



unsigned long currentMillis;
unsigned long previousMillis = 0;   
const long interval = 100;    

//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
void setup() 
{ 
 pinMode(Pin1, OUTPUT);  
 pinMode(Pin2, OUTPUT);  
 pinMode(Pin3, OUTPUT);  
 pinMode(Pin4, OUTPUT);  
 pinMode(ledPin, OUTPUT);
 pinMode(HomeSwitch, INPUT);

  while (!Serial); // for Leonardo/Micro/Zero

  Serial.begin(115200);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
  }
  // following line sets the RTC to the date & time this sketch was compiled
   rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // This line sets the RTC with an explicit date & time, for example to set
  // January 21, 2014 at 3am you would call:
  // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));

 
 digitalWrite(ledPin, HIGH);
 delay(50);
 digitalWrite(ledPin, LOW);
 delay(50);
 digitalWrite(ledPin, HIGH);
 delay(50);
 digitalWrite(ledPin, LOW);
 delay(50);
 digitalWrite(ledPin, HIGH);
 delay(50);
 digitalWrite(ledPin, LOW);
 delay(50);
 digitalWrite(ledPin, HIGH);
 delay(50);
 digitalWrite(ledPin, LOW);
 delay(1000);
 
 Find_home();
 
 digitalWrite(ledPin, HIGH);
 delay(50);
 digitalWrite(ledPin, LOW);
 delay(50);
 digitalWrite(ledPin, HIGH);
 delay(50);
 digitalWrite(ledPin, LOW);
 delay(1000);

///////////////////////////////////////////// 
//calculations
/////////////////////////////////////////////

StepsforSelectedRotation = ((StepsPerRotation / 360) * DegreeForRotation);
 Serial.println("//////////////////////// ");
 Serial.println(StepsforSelectedRotation);
StepsforSelectedRotation = round(StepsforSelectedRotation);
 Serial.println("//////////////////////// ");
 Serial.print("Number of Steps :");
 Serial.println(StepsforSelectedRotation);

SecondsToRotate = HoursToRotate * 60 *60 ;
MilisecondToRotate = SecondsToRotate * 1000; 


DelayBetweenStep = (MilisecondToRotate / StepsforSelectedRotation);
 Serial.println("//////////////////////// ");
  Serial.print("Delay Between Each Step:");
 Serial.println(DelayBetweenStep);



} 

//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
 void loop() 
{ 
Serial.println("//////////////////////// ");
Serial.print("Delay Between Step: ");
Serial.println(DelayBetweenStep);
  
  DateTime now = rtc.now();
  GetTime();
  unsigned long currentMillis = millis();

  


  Step(CW,StepsforSelectedRotation,DelayBetweenStep);

  delay(1000);

  Find_home();

  delay(1000);
    
  
}

//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
void Step(int Direction,int Steps, int Speed_delay){

for (int i=0; i< Steps; i++){ 
  if(Direction == CW){ 
     _step++; 
    Serial.println("//////////////////////// ");
    Serial.print("Step Clockwise: ");
    Serial.print (i);
    Serial.print (" Of ");
    Serial.println (StepsforSelectedRotation);

   }
   
  if(Direction == CCW){ 
     _step--; 
   Serial.println("//////////////////////// ");
   Serial.println("Step Counter Clockwise: ");
   Serial.print (i);
   Serial.print (" Of ");
   Serial.println (StepsforSelectedRotation);
   
   }
    
   if(_step>7){               // overflow reset
     _step=0; 
   } 
   if(_step<0){ 
     _step=7; 
   } 

  switch(_step){ 
     case 0: 
       digitalWrite(Pin1, LOW);  
       digitalWrite(Pin2, LOW); 
       digitalWrite(Pin3, LOW); 
       digitalWrite(Pin4, HIGH); 
     break;  
     case 1: 
       digitalWrite(Pin1, LOW);  
       digitalWrite(Pin2, LOW); 
       digitalWrite(Pin3, HIGH); 
       digitalWrite(Pin4, HIGH); 
     break;  
     case 2: 
       digitalWrite(Pin1, LOW);  
       digitalWrite(Pin2, LOW); 
       digitalWrite(Pin3, HIGH); 
       digitalWrite(Pin4, LOW); 
     break;  
     case 3: 
       digitalWrite(Pin1, LOW);  
       digitalWrite(Pin2, HIGH); 
       digitalWrite(Pin3, HIGH); 
       digitalWrite(Pin4, LOW); 
     break;  
     case 4: 
       digitalWrite(Pin1, LOW);  
       digitalWrite(Pin2, HIGH); 
       digitalWrite(Pin3, LOW); 
       digitalWrite(Pin4, LOW); 
     break;  
     case 5: 
       digitalWrite(Pin1, HIGH);  
       digitalWrite(Pin2, HIGH); 
       digitalWrite(Pin3, LOW); 
       digitalWrite(Pin4, LOW); 
     break;  
       case 6: 
       digitalWrite(Pin1, HIGH);  
       digitalWrite(Pin2, LOW); 
       digitalWrite(Pin3, LOW); 
       digitalWrite(Pin4, LOW); 
     break;  
     case 7: 
       digitalWrite(Pin1, HIGH);  
       digitalWrite(Pin2, LOW); 
       digitalWrite(Pin3, LOW); 
       digitalWrite(Pin4, HIGH); 
     break;  
     default: 
       digitalWrite(Pin1, LOW);  
       digitalWrite(Pin2, LOW); 
       digitalWrite(Pin3, LOW); 
       digitalWrite(Pin4, LOW); 
     break;  
 } 
 
 delay(Speed_delay); 
 Serial.print("Delay Between Step: ");
 Serial.println(Speed_delay);
 Serial.println ("");
}
}

/////////////////////////////////////////////////////////
void Find_home(void){
while(digitalRead(HomeSwitch)==1){                      // test limit switch 
  Step(CCW,1,0);                                        // move CCW to limit switch one step at a time without delay. 
}
Serial.print("FOUND HOME");
return; 
}
/////////////////////////////////////////////////////////
void GetTime(void){
 DateTime now = rtc.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
}

if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }