0% found this document useful (0 votes)
23 views2 pages

Oled Date Time

This document contains an Arduino sketch that interfaces with an OLED display and a real-time clock (RTC) module. It sets an alarm for 10:30:00, activating a digital pin when the time is reached, while continuously displaying the current date and time on the OLED screen. The code includes initialization for the display and RTC, as well as a loop to update the display every second.

Uploaded by

claussimon1418
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Oled Date Time

This document contains an Arduino sketch that interfaces with an OLED display and a real-time clock (RTC) module. It sets an alarm for 10:30:00, activating a digital pin when the time is reached, while continuously displaying the current date and time on the OLED screen. The code includes initialization for the display and RTC, as well as a loop to update the display every second.

Uploaded by

claussimon1418
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

​#include <Adafruit_GFX.

h>
#include <Adafruit_SSD1306.h>
#include <RTClib.h>
#include <Wire.h>

// OLED screen dimensions


#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

// Alarm pin definition


#define ALARM_PIN 4

// OLED display object


Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// RTC object
RTC_DS3231 rtc;

void setup() {
Serial.begin(9600);
// Initialize the OLED screen
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64 OLED
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}

// Initialize the RTC module


if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}

// Uncomment this line to set the RTC to the current computer time
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

// Set the digital pin for the alarm as an output


pinMode(ALARM_PIN, OUTPUT);
}

void loop() {
// Get the current time from the RTC
DateTime now = rtc.now();

// Check if the current time matches the alarm time (10:30:00)


if (now.hour() == 10 && now.minute() == 30 && now.second() == 0) {
// If the alarm time is met, set the digital pin HIGH
digitalWrite(ALARM_PIN, HIGH);
} else {
// Otherwise, keep the digital pin LOW
digitalWrite(ALARM_PIN, LOW);
}

// Clear the OLED display


display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);

// Print the date to the OLED


display.setCursor(0, 0);
display.print(now.month(), DEC);
display.print("/");
display.print(now.day(), DEC);
display.print("/");
display.println(now.year(), DEC);

// Print the current time to the OLED


display.setTextSize(2);
display.setCursor(0, 20);
if (now.hour() < 10) {
display.print("0");
}
display.print(now.hour(), DEC);
display.print(":");
if (now.minute() < 10) {
display.print("0");
}
display.print(now.minute(), DEC);
display.print(":");
if (now.second() < 10) {
display.print("0");
}
display.println(now.second(), DEC);

// Display the buffer on the OLED


display.display();
delay(1000); // Wait one second before updating again
}

You might also like