Let’s look at this function to get the time: (I’ve taken out the useless function prototype)
int getTime()
{
Wire.beginTransmission(DS1307_CTRL_ID);
Wire.write((uint8_t)0x00);
Wire.endTransmission();
Wire.requestFrom(DS1307_CTRL_ID, constNumberOfFields);
Second = bcd2dec(Wire.read() ); // (0-59)
Minute = bcd2dec(Wire.read() ); // (0-59)
Hour = bcd2dec(Wire.read() ); //assumes 24hr clock (0-23)
Day = bcd2dec(Wire.read() ); // (1-31)
Month = bcd2dec(Wire.read() ); // (1-12)
Year = bcd2dec(Wire.read() );
Year = Year + 2000; // RTC year 0 is year 2000
if (time < timeToFeed && time > timeToClose)
return true;
else
return false;
}
So this pulls in all the pieces of the time, then does nothing with them. Instead it either returns true or false. What time is true? What time is false?
Really though, it always returns false. Since timeToFeed and timeToClose were declared at global scope and have never been given any value anywhere else in the code, both of those variables are 0. The variable Time is also initialized to 0 and is never changed anywhere else that I can find in the program. So all three variables are 0, Time is not less than timeToFeed and the if statement comes out false so getTime returns false. Always. Never will it return anything other than false (or actually 0 since it is declared to return an int and not a bool).
Now let’s carry that result through to this code:
void loop()
{
currentTime = getTime(); //if (BirdShoudlBeFed)
if (currentTime == timeToClose)
CloseFeeder();
if (currentTime == timeToFeed)
OpenFeeder();
digitalClockDisplay();
}
Now getTime returns 0 so currentTime will always be 0. So is timeToClose and timeToFeed since you’ve never given them any values anywhere. So both if statements come out true since 0 == 0. So this loop will run the functions CloseFeeder() and OpenFeeder() over and over and over again.
CloseFeeder will :
void CloseFeeder(){
myservo.attach(constServoSignalPin); // attaches the servo on pin 9 to the servo object
myservo.write(28); // tell servo to go to position in variable 'angle'
delay(10000); // waits 10 seconds between servo movement
myservo.detach();
}
move the servo and wait ten seconds.
Then OpenFeeder will also move the servo and wait ten seconds.
So it sounds like with the program as written, the servo should move to one position, wait ten seconds, then move to the other position and wait ten seconds, then repeat ad infinitum.
Now, to me it would make sense to have the getTime function actually return a time instead of true or false. It would make sense that timeToClose and timeToFeed should have some value other than 0.