Components and supplies
1
USB-A to B Cable
1
Flash Memory Card, SDHC Card
1
cr1220 batery
1
data logger shield
1
Arduino UNO
Apps and platforms
1
Arduino IDE
Project description
Code
clock
c_cpp
Comments
Only logged in users can leave comments
Components and supplies
USB-A to B Cable
Flash Memory Card, SDHC Card
cr1220 batery
data logger shield
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
clock
c_cpp
1#include <Wire.h> 2#include <ds3231.h> 3#include <SPI.h> 4#include <SD.h> 5 6const char* filename = "time.txt"; 7 8File file; 9 10struct ts t; 11 12void setup() { 13 Serial.begin(9600); 14 Wire.begin(); 15 DS3231_init(DS3231_INTCN); 16 if (!SD.begin(10)) { 17 Serial.println("Error : Push the reset button"); 18 for (;;); 19 } 20 21 file = SD.open(filename, FILE_WRITE); 22 /*---------------------------------------------------------------------------- 23 In order to synchronise your clock module, insert timetable values below ! 24 ----------------------------------------------------------------------------*/ 25 t.hour = 12;//hours 26 t.min = 54;//minutes 27 t.sec = 20;//seconds 28 t.mday = 2;//date 29 t.mon = 12;// month 30 t.year = 2120;//year 31 32 DS3231_set(t); 33} 34 35void loop() { 36 DS3231_get(&t); 37 Serial.print("Date : "); 38 file.print("Date : "); 39 file.flush(); 40 Serial.print(t.mday); 41 file.print(t.mday); 42 file.flush(); 43 Serial.print("/"); 44 file.print("/"); 45 file.flush(); 46 Serial.print(t.mon); 47 file.print(t.mon); 48 file.flush(); 49 Serial.print("/"); 50 file.print("/"); 51 file.flush(); 52 Serial.print(t.year); 53 file.print(t.year); 54 file.println(); 55 file.flush(); 56 Serial.print("\ Hour : "); 57 file.print("\ Hour : "); 58 file.flush(); 59 Serial.print(t.hour); 60 file.print(t.hour); 61 file.flush(); 62 Serial.print(":"); 63 file.print(":"); 64 file.flush(); 65 Serial.print(t.min); 66 file.print(t.min); 67 file.flush(); 68 Serial.print("."); 69 file.print("."); 70 file.flush(); 71 Serial.println(t.sec); 72 file.println(); 73 file.flush(); 74 75 delay(1000); 76}
Comments
Only logged in users can leave comments