Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
987 B
1
Indexable
Never
/*
Rafał Dubiel, Mateusz Kotowicz
*/

#include <DS3231.h>
#include <Wire.h>
#include <LCD_I2C.h>

#define I2C1_SDA_PIN 2
#define I2C1_SCL_PIN 3

DS3231 myRTC(Wire1);

bool century = false;
bool h12Flag;
bool pmFlag;

LCD_I2C lcd(0x27, 16, 2);


void setup() {

  Serial.begin(115200);
  while (!Serial){};
  Serial.println("RTC DS 3231.");
  Wire1.setSDA(I2C1_SDA_PIN);
  Wire1.setSCL(I2C1_SCL_PIN);
  Wire1.begin();


  lcd.begin();
  lcd.backlight();

  myRTC.setYear(24);
  myRTC.setMonth(6);
  myRTC.setDate(7);
  myRTC.setHour(13);
  myRTC.setMinute(57);
  myRTC.setSecond(0);
  
}

void loop() {

  lcd.print(20);
  lcd.print(myRTC.getYear(), DEC);
  lcd.print("-");
  lcd.print(myRTC.getMonth(century), DEC);
  lcd.print("-");
  lcd.print(myRTC.getDate(), DEC);

  lcd.setCursor(0, 1);
  lcd.print(myRTC.getHour(h12Flag, pmFlag), DEC);
  lcd.print(":");
  lcd.print(myRTC.getMinute(), DEC);
  lcd.print(":");
  lcd.print(myRTC.getSecond(), DEC);
  delay(1000);
  lcd.clear();

}
Leave a Comment