I've read a blog and a number of posts in the forum on this subject but am still not able to use one library inside another. The library I'm trying to use is TimeLib; I have it and Time.h and Time.cpp in a directory called Time under the libraries folder.
In another folder inside libraries I have D1302 and the .h and .cpp files shown below.
I've also included the sketch and the compiler output.
Can anyone tell me what stupid thing I'm doing that is keeping me from moving forward?
1302.h File:
#ifndef DS1302_h
#define DS1302_h
#include "Arduino.h"
#include "../Time/TimeLib.h"
class DS1302
{
public:
DS1302(int _SCLK_Pin, int _IO_Pin, int _CE_Pin); //Constructor assumes no battery recharging
private:
int _DS1302_SCLK_Pin; // Arduino pin for the Serial Clock
int _DS1302_IO_Pin; // Arduino pin for the Data I/O
int _DS1302_CE_Pin; // Arduino pin for the Chip Enable
boolean _batRecharge; //true if will recharge, false if will not recharge
int _DS1302_Trickle_h; //0x01 if will recharge, 0x00 if will not recharge
void fill_DS1302_struct(); //used to fill the structure
struct _DS1302_struct
{
uint8_t Seconds:4; // low decimal digit 0-9
};
// Macros to convert the bcd values of the registers to normal integer variables. The code uses separate
//variables for the high byte and the low byte of the bcd, so these macros handle both bytes separately.
#define bcd2bin(h,l) (((h)*10) + (l))
#define bin2bcd_h(x) ((x)/10)
#define bin2bcd_l(x) ((x)%10)
};
#endif
1302.cpp File:
#include "Arduino.h"
#include "../Time/TimeLib.h"
#include "DS1302.h"
DS1302::DS1302(int _SCLK_Pin, int _IO_Pin, int _CE_Pin)
{
_DS1302_SCLK_Pin = _SCLK_Pin; // Arduino pin for the Serial Clock
_DS1302_IO_Pin = _IO_Pin; // Arduino pin for the Data I/O
_DS1302_CE_Pin = _CE_Pin; // Arduino pin for the Chip Enable
_DS1302_Trickle_h = 0x00;
_DS1302_struct rtc;
}
DS1302::DS1302(int _SCLK_Pin, int _IO_Pin, int _CE_Pin, boolean _batRecharge)
{
_DS1302_SCLK_Pin = _SCLK_Pin; // Arduino pin for the Serial Clock
_DS1302_IO_Pin = _IO_Pin; // Arduino pin for the Data I/O
_DS1302_CE_Pin = _CE_Pin; // Arduino pin for the Chip Enable
if (_batRecharge)
{
_DS1302_Trickle_h = 0x01;
}
else
{
_DS1302_Trickle_h = 0x00;
}
}
void DS1302::fill_DS1302_struct()
{
// Set your own time and date in these variables.
int _seconds = seconds();
// Set a time and date
// This also clears the CH (Clock Halt) bit,
// to start the clock.
// Fill the structure with zeros to make
// any unused bits zero
_DS1302_struct rtc;
memset ((char *) &rtc, 0, sizeof(rtc));
rtc.Seconds = bin2bcd_l( _seconds);
}
Sketch File:
#include "TimeLib.h"
#include "DS1302.h"
int SCLK_Pin = 6;
int IO_Pin = 7;
int CE_Pin = 8;
boolean batRecharge = true;
DS1302 DS1302_1(SCLK_Pin, IO_Pin, CE_Pin);
DS1302 DS1302_2(SCLK_Pin, IO_Pin, CE_Pin, batRecharge);
void setup()
{
Serial.begin(9600); //Start Serial
Serial.println("<Arduino Ready...>");
}
void loop()
{
Serial.println("In Loop");
delay(10000);
}
Select compiler output:
M:\Arduino\Sketches\libraries\DS1302\DS1302.cpp:102:28: error: 'seconds' was not declared in this scope
int _seconds = seconds();
^
Using library Time at version 1.5 in folder: M:\Arduino\Sketches\libraries\Time
Using library DS1302 in folder: M:\Arduino\Sketches\libraries\DS1302 (legacy)
exit status 1
Error compiling for board Arduino/Genuino Uno.