Giter Club home page Giter Club logo

ds1337rtc's Introduction

Here is some example code for this library, I will expand the README more as I get an opportunity.

#include <DS1337RTC.h>
#include <Time.h>
#include <Wire.h>
#define alarmPin 12

char *monthName[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

void setup(){
  pinMode(alarmPin, INPUT);
  digitalWrite(alarmPin,HIGH);

  Serial.begin(9600);

  tmElements_t tmSet;
  tmSet.Year = 2011 - 1970;
  tmSet.Month = 7;
  tmSet.Day = 3;
  tmSet.Hour = 20;
  tmSet.Minute = 13;
  tmSet.Second = 0;
  RTC.set(makeTime(tmSet), CLOCK_ADDRESS); // set the clock

  tmSet.Second = 4;
  RTC.set(makeTime(tmSet), ALARM1_ADDRESS); // set the alarm for 4 seconds later

  RTC.enableAlarm(ALARM1_ADDRESS);

  RTC.freqSelect(1);  // set the squarewave freq on alarm pin b to 4.096kHz
}
  
void loop(){
  time_t alarm = RTC.get(ALARM1_ADDRESS);  // get the time the alarm is set for
  tmElements_t alarmSet;
  breakTime(alarm, alarmSet);

  //print the time using Time.h
  Serial.print(day());
  Serial.print(" ");
  Serial.print(monthName[month() - 1]);
  Serial.print(" ");
  Serial.print(year());
  Serial.print(" ");
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print("\t");

  // print the alarm time
  Serial.print("ALARM1: ");
  Serial.print((int)alarmSet.Day);
  Serial.print(" ");
  Serial.print((int)alarmSet.Hour);
  printDigits(alarmSet.Minute);
  printDigits(alarmSet.Second);
  Serial.print("\t");
  
  if(digitalRead(alarmPin) == HIGH){  //pin is set low when alarm is triggered
    Serial.println("ALARM off");
  }else{
    Serial.println("ALARM on");
    RTC.resetAlarms();
  }
  
  delay(1000);
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

ds1337rtc's People

Contributors

etrombly avatar

Watchers

James Cloos avatar T. Garthoff avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.