stickyBUG Code

The following sample code requires the rtcBUG library.

Source Code

// import libraries...
#include <Wire.h>
#include <rtcBUG.h>

// create rtcBUG object...
rtcBUG bug = rtcBUG();

// pads an int with leading zero, if required...
void printWithPad(unsigned int value, byte padCount) {
  for (byte pad = 0; pad < padCount - String(value,DEC).length(); pad++) Serial.print("0");
  Serial.print(value, DEC);
}

// program initialisation...
void setup () {
    Serial.begin(9600);
    bug.begin();

    // use this routine to set date and time - if you have a battery
    // installed in your rtcBUG, the recompile and program again with
    // this line commented out...
    bug.adjust(DateTime("Dec 06 2014", "09:54:00"));
}

// main program entry point...
void loop () {
    DateTime now = bug.now();

   // display date... 
    printWithPad(now.day(), 2); Serial.print('/');
    printWithPad(now.month(), 2); Serial.print('/');
    printWithPad(now.year(), 4); Serial.print(' ');

    // display time...
    printWithPad(now.hour(), 2); Serial.print(':');
    printWithPad(now.minute(), 2); Serial.print(':');
    printWithPad(now.second(), 2); Serial.println();
    delay(1000);
}