servo not working in alarm time?

servo not working in alarm time. servo runing 4:14:24. real alarm set 4:15:00

]#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
#include <TimeAlarms.h>
#include <Time.h>
#include <Servo.h>

Servo myservo1;
Servo myservo2;

RTC_DS1307 RTC;
LiquidCrystal lcd(10, 11, 12, 5, 6, 7);
int motorPin = 13;
int lastHour = 24;
int lastMinute = 60;

bool feedPet = false;
unsigned long feedTime = 0;
unsigned long lastPrintTime = 0;

struct FeedTime{
  int hour, minute;
};

FeedTime amFeed = {4,15};  // i.e. 10:00am
FeedTime pmFeed = {17,30};  // i.e. 5:30pm

void setup ()
{
 // pinMode(motorPin, OUTPUT);
   myservo1.attach(3);
  myservo2.attach(4);
  Serial.begin(9600);
  lcd.begin(16, 2);
  Wire.begin();
  RTC.begin();
  if (! RTC.isrunning())
  {
    lcd.println("RTC NOT Running!");
    RTC.adjust(DateTime((__DATE__), (__TIME__)));
  }
}

void loop ()
{
  DateTime now = RTC.now();
  FeedTime currentTime;
  currentTime.hour = now.hour();
  currentTime.minute = now.minute();
  if((currentTime.minute != lastMinute) && (((currentTime.hour == amFeed.hour) && (currentTime.minute == amFeed.minute)) || ((currentTime.hour == pmFeed.hour) && (currentTime.minute == pmFeed.minute))))
  {
    feedTime = millis();
    feedPet = true;
  }
  lastMinute = currentTime.minute;
  if (feedPet)
  {
    turnFeeder();
  }
  if (millis() - lastPrintTime > 1000UL)
  {
    lcd.setCursor(0, 0);
    char nowDate[24] = "";
    sprintf(nowDate, "DATE: %02d/%02d/%d", now.month(), now.day(), now.year());
    lcd.print(nowDate);
    // display the time
    lcd.setCursor(0, 1);
    char nowTime[24] = "";
    sprintf(nowTime, "Time: %02d:%02d:%02d", now.hour(), now.minute(), now.second());
    lcd.print(nowTime);
    lastPrintTime = millis();
  }
}

void turnFeeder(){
    for(feedTime = 0; feedTime <= 180; feedTime += 1)
  {                                 
    myservo1.write(feedTime);   
    myservo2.write(feedTime);
    delay(10);                     
  }
  for(feedTime = 180; feedTime>=0; feedTime-=1)     
  {                               
    myservo1.write(feedTime);             
    myservo2.write(feedTime);
    delay(10);                       
  }

  Serial.println("Alarm");   
}

Moderator edit: code tags, CODE TAGS, CODE TAGS. How difficult is this?

You posted using quote tags, not code tags. That's why it's in funny italics. Please go back and fix it.

Is there a question here?

Yes, the OP is saying that the servo doesn't actuate at the correct time.

You're doing this every time you go through loop(). It should be inside the statement that checks for a new minute.

  lastMinute = currentTime.minute;

This:

    feedTime = millis();

and this:

    for(feedTime = 0; feedTime <= 180; feedTime += 1)
  {                                 
    myservo1.write(feedTime);   
    myservo2.write(feedTime);
    delay(10);                     
  }
  for(feedTime = 180; feedTime>=0; feedTime-=1)     
  {                               
    myservo1.write(feedTime);             
    myservo2.write(feedTime);
    delay(10);                       
  }

use the same variable for two completely different purposes.

There is no way that feedTime relates to a loop index or to a servo position.

Why is the TimeAlarm header file included? You don’t create any Alarms.

I still do not understand.
please provide the code that has been fixed.
thanks. :frowning:

gustijuandi:
I still do not understand.
please provide the code that has been fixed.
thanks. :frowning:

Are you paying? I'll bill you for the time I already spent on it this morning.