DS3231 RTC Module & OLED Display 0.96" I2C 128x64 SSD1306 with Arduino | English Subtitle Code : code is on the comment below. Facebook : / doit20-104218935882053 Please Subscribe my Channel. ThankYou!
Пікірлер: 3
@doit.204 ай бұрын
#include #include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); RTC_DS3231 rtc; void setup() { Serial.begin(9600); // Initialize the OLED display if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64 Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever } // Initialize the DS3231 RTC if (!rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); } if (rtc.lostPower()) { Serial.println("RTC lost power, let's set the time!"); // The following line sets the RTC to the date & time this sketch was compiled rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Uncomment the next line to set the date & time manually // rtc.adjust(DateTime(2024, 5, 25, 12, 0, 0)); } display.display(); delay(2000); // Pause for 2 seconds display.clearDisplay(); } void loop() { DateTime now = rtc.now(); // Clear the buffer display.clearDisplay(); display.setTextSize(2); // Larger text size display.setCursor(22, 0); display.print("DoIt.20"); // Display the current date display.setTextSize(1); // Larger text size display.setCursor(0, 25); display.print("Date: "); display.print(now.year(), DEC); display.print('/'); if (now.month() < 10) display.print('0'); display.print(now.month(), DEC); display.print('/'); if (now.day() < 10) display.print('0'); display.print(now.day(), DEC); // Display the current time display.setTextSize(2); // Larger text size display.setTextColor(SSD1306_WHITE); display.setCursor(0, 40); // display.print("Time: "); if (now.hour() < 10) display.print('0'); display.print(now.hour()); display.print(':'); if (now.minute() < 10) display.print('0'); display.print(now.minute()); display.print(':'); if (now.second() < 10) display.print('0'); display.print(now.second()); // Show the buffer on the display display.display(); // Wait for a second before updating delay(1000); }