#include <Wire.h> // Needed for I2C protocol (RTC uses I2C)
#include "RTClib.h" //Good Library for RTC functions
#include <Time.h> // Needed for time_t variables and tmElements
RTC_DS3231 rtcVM; // From the RTClib library for use with an DS3231 RTC. Creates an object called rtcVM
DateTime nowVM; // Declare a Date Time object that will be used to hold the current time
time_t nowUniVM;// Declare a time_t object (Unix time) which is a float value (good for straight comparisons) to hold current time
time_t starter;// Declare a time_t object for the start time (time_t)
tmElements_t MagStart; // Declare a tmElement_t object to manually input the start Time
//FILL OUT START TIME AND DATE FOR FIRST SAMPLE (NO LEADIN ZEROS--"8" not "08")
byte startHour = 17;
byte startMin = 58;
byte startSec = 0;
byte startDay = 12;
byte startMonth = 10;
int twoDigYear = 16; // Enter last two digits of year
byte startYear = twoDigYear + 30 ; // This is a little confusing. This is the year offset from 1970 (AKA 2016 should be input as 46. Or just add 30 to last two digits).
void setup() {
Serial.begin(9600);
Wire.begin();
rtcVM.begin();
// Creates a tmElement by putting together all of Maggies Start Time and Dates
MagStart.Hour=startHour;
MagStart.Minute = startMin;
MagStart.Second = startSec;
MagStart.Day = startDay;
MagStart.Month = startMonth;
MagStart.Year = startYear;
// Takes the tmElement and converts it to a time_t variable. Which can now be compared to the current (now) unix time
starter = makeTime(MagStart);
// Start message
Serial.println("Start time is: ");
Serial.print(hour(starter));
Serial.print(":");
Serial.print(minute(starter));
Serial.print(":");
Serial.print(second(starter));
Serial.print(" ");
Serial.print(month(starter));
Serial.print("/");
Serial.print(day(starter));
Serial.print("/");
Serial.println(year(starter));
Serial.println("****************************");
}
void loop() {
nowVM = rtcVM.now(); // get current time and hold in "nowVM"
time_t nowUniVM = nowVM.unixtime(); // Calculate current time in Unix time
samplerStarter();
// RTC Get and Display
DateTime now = rtcVM.now();// Getting the current Time and storing it into a DateTime object
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(3000);
//Use these 2 to check the numerical values for comparisons
Serial.println(starter);
Serial.println(nowUniVM);
}
void samplerStarter() {
if (starter < nowUniVM) {
//if (1 < 2) {
Serial.println("Start Time");
}
}