Skip to content

Commit

Permalink
Added Arduino example
Browse files Browse the repository at this point in the history
  • Loading branch information
jhedwardyang committed May 25, 2016
1 parent 78b5ebf commit b95a459
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
69 changes: 69 additions & 0 deletions examples/Print
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Copyright (c) 2016 Edward Yang
* All rights reserved.
*
*/

#include "DS3231.h"

/*
* Example program for Arduino
*/

void setup() {
Wire.begin();
Serial.begin(9600);
// Set the initial time
ts t;
t.sec = 0;
t.min = 0;
t.hour = 0;
t.dayOfWeek = 4;
t.day = 25;
t.month = 5;
t.year = 16;
set(t);
}

void print(ts t) {
Serial.print("20");
Serial.print(t.year, DEC);
Serial.print("/");
Serial.print(t.month, DEC);
Serial.print("/");
Serial.print(t.day, DEC);
Serial.print(" ");

if (t.hour < 10) {
Serial.print("0");
}
Serial.print(t.hour, DEC);
Serial.print(":");
if (t.min < 10) {
Serial.print("0");
}
Serial.print(t.min, DEC);
Serial.print(":");
if (t.sec < 10) {
Serial.print("0");
}
Serial.print(t.sec, DEC);
Serial.print("\n");
}

void loop() {
ts t;
get(&t);
print(t);
delay(1000);
}
2 changes: 1 addition & 1 deletion lib/ds3231.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct ts {
uint8_t sec;
uint8_t min;
uint8_t hour;
uint8_t dayOfWeek;
uint8_t dayOfWeek; // 1 = Sunday, 7 = Saturday
uint8_t day;
uint8_t month;
uint8_t year;
Expand Down

0 comments on commit b95a459

Please sign in to comment.