Keyestudio ARDUINO maker learning kit Manual page 149

Table of Contents

Advertisement

Example sketch for interfacing with the DS1302 timekeeping chip.
Copyright (c) 2009, Matt Sparks
All rights reserved.
http://quadpoint.org/projects/arduino-ds1302
*/
#include <stdio.h>
#include <string.h>
#include <DS1302.h>
/* Set the appropriate digital I/O pin connections */
uint8_t CE_PIN
= 5;
uint8_t IO_PIN
= 6;
uint8_t SCLK_PIN = 7;
/* Create buffers */
char buf[50];
char day[10];
/* Create a DS1302 object */
DS1302 rtc(CE_PIN, IO_PIN, SCLK_PIN);
void print_time()
{
/* Get the current time and date from the chip */
Time t = rtc.time();
/* Name the day of the week */
memset(day, 0, sizeof(day)); /* clear day buffer */
switch (t.day) {
case 1:
strcpy(day, "Sunday");
break;
case 2:
strcpy(day, "Monday");
break;
case 3:
strcpy(day, "Tuesday");
break;
case 4:
keyestudio
www.keyestudio.cc
147

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ARDUINO maker learning kit and is the answer not in the manual?

Table of Contents