RTC with Servo Motor

Hi,

My group and I are struggling with a problem with our Arduino code because we are trying to incorporate the Servo motor to activate when it is a certain time. The main question is with the for loop because we do not know how to convert the time to a data that the RTC will recognize. Here is our progress so far and thanks!

#include <DS1302.h>
#include <Servo.h>

// Init the DS1302
DS1302 rtc(2, 3, 4);

Servo myservo;
int pos = 0;

void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);

// Setup Serial connection
Serial.begin(9600);

// The following lines can be commented out to use the values already stored in the DS1302
// rtc.setDOW(SUNDAY); // Set Day-of-Week
// rtc.setTime(8, 53, 0); // Set the time (24hr format)
// rtc.setDate(03, 11, 2018); // Set the date

myservo.attach(9);
}

void loop()
{
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");

// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");

// Send time
Serial.println(rtc.getTimeStr());

// Wait one second before repeating
delay (1000);

// if time is greater than or equal to 8 PM, have servo turn 180 degrees
if () {
for (pos = 0; pos <= 180; pos+=1){
myservo.write(pos);
}
}

else if {
for (pos = 180; pos >= 0; pos -=1){
myservo.write(pos);
}
}
}

So look at the documentation or the DS1302.h file to find out how to get the hour from the clock.

Note that it's always after 8pm. It was 8pm yesterday. You need another time. Like midnight or 6am. Then it's often easier to write the if statement the other way around:

  if(hour > 6 && hour <20) {
    //daytime 
    myservo.write(0);
  } else {
    //night time
    myServo.write(180);
  }

I attached the header the file because I could not find exactly what I needed. I appreciate any help.

/*
DS1302.h - Arduino library support for the DS1302 Trickle Charge Timekeeping Chip
Copyright (C)2010 Henning Karlsen. All right reserved

You can find the latest version of the library at
http://www.henningkarlsen.com/electronics

This library has been made to easily interface and use the DS1302 RTC with
the Arduino.

If you make any modifications or improvements to the code, I would appreciate
that you share the code with me so that I might include it in the next release.
I can be contacted through Electronics - Henning Karlsen

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DS1302_h
#define DS1302_h

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#define FORMAT_SHORT 1
#define FORMAT_LONG 2

#define FORMAT_LITTLEENDIAN 1
#define FORMAT_BIGENDIAN 2
#define FORMAT_MIDDLEENDIAN 3

#define MONDAY 1
#define TUESDAY 2
#define WEDNESDAY 3
#define THURSDAY 4
#define FRIDAY 5
#define SATURDAY 6
#define SUNDAY 7

#define TCR_D1R2K 165
#define TCR_D1R4K 166
#define TCR_D1R8K 167
#define TCR_D2R2K 169
#define TCR_D2R4K 170
#define TCR_D2R8K 171
#define TCR_OFF 92

class Time
{
public:
uint8_t hour;
uint8_t min;
uint8_t sec;
uint8_t date;
uint8_t mon;
uint16_t year;
uint8_t dow;

Time();
};

class DS1302_RAM
{
public:
byte cell[31];

DS1302_RAM();
};

class DS1302
{
public:
DS1302(uint8_t ce_pin, uint8_t data_pin, uint8_t sclk_pin);
Time getTime();
void setTime(uint8_t hour, uint8_t min, uint8_t sec);
void setDate(uint8_t date, uint8_t mon, uint16_t year);
void setDOW(uint8_t dow);

char *getTimeStr(uint8_t format=FORMAT_LONG);
char *getDateStr(uint8_t slformat=FORMAT_LONG, uint8_t eformat=FORMAT_LITTLEENDIAN, char divider='.');
char *getDOWStr(uint8_t format=FORMAT_LONG);
char *getMonthStr(uint8_t format=FORMAT_LONG);

void halt(bool value);
void writeProtect(bool enable);
void setTCR(uint8_t value);

void writeBuffer(DS1302_RAM r);
DS1302_RAM readBuffer();
void poke(uint8_t addr, uint8_t value);
uint8_t peek(uint8_t addr);

private:
uint8_t _ce_pin;
uint8_t _data_pin;
uint8_t _sclk_pin;
uint8_t _burstArray[8];

uint8_t _readByte();
void _writeByte(uint8_t value);
uint8_t _readRegister(uint8_t reg);
void _writeRegister(uint8_t reg, uint8_t value);
void _burstRead();
uint8_t _decode(uint8_t value);
uint8_t _decodeH(uint8_t value);
uint8_t _decodeY(uint8_t value);
uint8_t _encode(uint8_t vaule);
};
#endif