Organize and Share your Electronics the way you want. Sign-Up for a free account now. It takes only 30 seconds!

OpenAccess RTC functions

OpenAccess RTC functions

These declares are for the i2c eeprom and realtime clock:

//I2C stuff
#include <Wire.h> // Needed for I2C Connection to the DS1307 date/time chip
#include <DS1307.h> // DS1307 RTC Clock/Date/Time chip library
#include <E24C1024.h> // Needed for the onboard EEPROM
uint8_t second, minute, hour, dayOfWeek, dayOfMonth, month, year; // Global RTC clock variables. Can be set using DS1307.getDate function.
DS1307 ; // RTC Instance

Those are used in their own functions, this one takes commands from the serial and does RTC things with them:

// uses RTC
//format: RTC;<0=write, 1=read>;<second, 0-59 (write only)>;<minute,0-59 (write only)>;<hour, 1-23 (write only)>;<dayOfWeek, 1-7 (write only)>;<dayOfMonth, 1-28/29/30/31 (write only)>;<month, 1-12 (write only)>;<year, 0-99 (write only)>
void SCmd_rtc()
{
char *arg;
//Serial.println(“rtc”);
arg = SCmd.next();
if (arg != NULL)
{
if(atoi(arg))
{
//Serial.println(“read rtc”);
//logDate();
Serial.println(logDate());//should be logging?
}
else
{
//Serial.println(“write rtc”);
arg = SCmd.next();
if (arg != NULL)
{
second=atoi(arg);
}
else
{
//Serial.println(“No second argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
minute=atoi(arg);
}
else
{
//Serial.println(“No minute argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
hour=atoi(arg);
}
else
{
//Serial.println(“No hour argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
dayOfWeek=atoi(arg);
}
else
{
//Serial.println(“No dow argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
dayOfMonth=atoi(arg);
}
else
{
//Serial.println(“No dom argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
month=atoi(arg);
}
else
{
//Serial.println(“No month argument”);
}
arg = SCmd.next();
if (arg != NULL)
{
year=atoi(arg);
}
else
{
//Serial.println(“No year argument”);
}
ds1307.setDateDs1307(second,minute,hour,dayOfWeek,dayOfMonth,month,year);
/* Sets the date/time (needed once at commissioning)
uint8_t second // 0-59
uint8_t minute // 0-59
uint8_t hour // 1-23
uint8_t dayOfWeek // 1-7
uint8_t dayOfMonth // 1-28/29/30/31
uint8_t month // 1-12
uint8_t year // 0-99
*/
}
}
else
{
//Serial.println(“No arguments”);
}
}

This next one returns the date in a print/logable form and is used all over the code to timestamp things:

String logDate()
{
String date;
ds1307.getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
date+=”20″;//hack
date+=year;
date+=”-“;
if(month < 10)
{
date+=”0″;
}
date+=month;
date+=”-“;
if(dayOfMonth < 10)
{
date+=”0″;
}
date+=dayOfMonth;
date+=’T’;
if(hour < 10)
{
date+=”0″;
}
date+=hour;
date+=”:”;
if(minute < 10)
{
date+=”0″;
}
date+=minute;
date+=”:”;
if(second < 10)
{
date+=”0″;
}
date+=second;
date+=” “;
switch(dayOfWeek){
case 1:
{
date+=”SUN”;
break;
}
case 2:
{
date+=”MON”;
break;
}
case 3:
{
date+=”TUE”;
break;
}
case 4:
{
date+=”WED”;
break;
}
case 5:
{
date+=”THU”;
break;
}
case 6:
{
date+=”FRI”;
break;
}
case 7:
{
date+=”SAT”;
break;
}
}
return date;
}

That’s it, that’s what the RTC is for: timestamps on things. This is part of the greater OpenAccess project.

Read more Here







 

More Articles to Read

DECA MAX®10 FPGA Evaluation Kit
DECA MAX®10 FPGA Evaluation Kit
An Arduino laser pinball machine
An Arduino laser pinball machine
CTCSS fingerprinting: A method for transmitter identification
CTCSS fingerprinting: A method for transmitter identification
TI DLP® Pico™ Technology for Aftermarket Head-up Displays
TI DLP® Pico™ Technology for Aftermarket Head-up Displays
Brute force computation for cheap log digital potentiometer
Brute force computation for cheap log digital potentiometer
Smart "Homer"
Smart "Homer"
A DIY Segway-style vehicle
A DIY Segway-style vehicle
Superbeta transistors inside: Die photos and analysis of the LM108 op amp
Superbeta transistors inside: Die photos and analysis of the LM108 op amp
Peeqo is a desktop bot that communicates through GIFs
Peeqo is a desktop bot that communicates through GIFs
Using a Programmable Input Multiplier to Minimize Integer Boundary Spurs
Using a Programmable Input Multiplier to Minimize Integer Boundary Spurs

Top


Shares