Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ds3231ts(void){
- Wire.begin();
- Serial.begin(9600);
- // set the initial time here:
- // DS3231 seconds, minutes, hours, day, date, month, year
- // setDS3231time(30,42,21,4,26,11,14);
- }
- /*void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year){
- // sets time and date data to DS3231
- Wire.beginTransmission(DS3231_I2C_ADDRESS);
- Wire.write(0); // set next input to start at the seconds register
- Wire.write(decToBcd(second)); // set seconds
- Wire.write(decToBcd(minute)); // set minutes
- Wire.write(decToBcd(hour)); // set hours
- Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
- Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
- Wire.write(decToBcd(month)); // set month
- Wire.write(decToBcd(year)); // set year (0 to 99)
- Wire.endTransmission();
- }*/
- void readDS3231time(byte *second, byte *minute, byte *hour, byte *dayOfWeek, byte *dayOfMonth, byte *month, byte *year){
- Wire.beginTransmission(DS3231_I2C_ADDRESS);
- Wire.write(0); // set DS3231 register pointer to 00h
- Wire.endTransmission();
- Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
- // request seven bytes of data from DS3231 starting from register 00h
- *second = bcdToDec(Wire.read() & 0x7f);
- *minute = bcdToDec(Wire.read());
- *hour = bcdToDec(Wire.read() & 0x3f);
- *dayOfWeek = bcdToDec(Wire.read());
- *dayOfMonth = bcdToDec(Wire.read());
- *month = bcdToDec(Wire.read());
- *year = bcdToDec(Wire.read());
- }
- void displayTime(void){
- byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
- // retrieve data from DS3231
- readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
- // send it to the serial monitor
- Serial.print(hour, DEC);
- // convert the byte variable to a decimal number when displayed
- Serial.print(":");
- if (minute<10){
- Serial.print("0");
- }
- Serial.print(minute, DEC);
- Serial.print(":");
- if (second<10){
- Serial.print("0");
- }
- Serial.print(second, DEC);
- Serial.print(" ");
- Serial.print(dayOfMonth, DEC);
- Serial.print("/");
- Serial.print(month, DEC);
- Serial.print("/");
- Serial.print(year, DEC);
- Serial.print(" Den: ");
- switch(dayOfWeek){
- case 1:
- Serial.println("Neděle");
- break;
- case 2:
- Serial.println("Pondělí");
- break;
- case 3:
- Serial.println("Úterý");
- break;
- case 4:
- Serial.println("Středa");
- break;
- case 5:
- Serial.println("Čtvrtek");
- break;
- case 6:
- Serial.println("Pátek");
- break;
- case 7:
- Serial.println("Sobota");
- break;
- }
- lcd.setCursor(3, 3);
- lcd.print("Cas : ");
- lcd.print(hour +1);
- lcd.print(":");
- if (minute<10){
- lcd.print("0");
- }
- lcd.print(minute);
- lcd.print(":");
- if (second<10){
- lcd.print("0");
- }
- lcd.print(second);
- //delay(1000);
- }
- void casocislo(void)
- {
- byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
- readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
- int timestamp = (hour + 1)*60 + minute ;
- Serial.println(timestamp);
- }
- void zobraz(void)
- {
- displayTime(); // display the real-time clock data on the Serial Monitor,
- casocislo();
- //delay(1000); // every second
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement