[HELP NEEDED] Changing the time on a rtc

I created word rtc in 2022 and the time has lagged behind, I need help updating the time to AEST. Someone helped write the code so not sure how to update the code myself.

Can someone please help me find the code used to change the time or on what to replace the current code with? Thanks :slight_smile:

Here's the full code:

#include <FastLED.h>

#include <DS3231.h>

#define NUM_LEDS 110

#define DATA_PIN 8

DS3231 rtc(SDA, SCL);

CRGB leds[NUM_LEDS];

// Init a Time-data structure

Time t;

void setup() {

FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

FastLED.setMaxPowerInVoltsAndMilliamps(5, 50);

// Setup Serial connection

Serial.begin(115200);

// Initialize the rtc object

rtc.begin();

// randomSeed(analogRead(0));

//rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));

//rtc.adjust(DateTime(2023, 12, 28, 10, 57, 0));

}

void loop() {

displayTime();

}

void displayTime() {

FastLED.clear();

// Get data from the DS3231

t = rtc.getTime();

int minute = t.min;

//int minute = 36;

int hour = t.hour;

if (hour >= 12) {

displayPM();

} else {

displayAM();

}

hour = hour % 12;

Serial.println(hour);

Serial.println(minute);

//int hour = 1;

if (hour == 0) {

hour = 1;

}

displayIT();

displayIS();

// now we display the appropriate minute counter

if ((minute > 4) && (minute < 10)) {

displayFIVE();

displayPAST();

Serial.print("Five Minutes ");

}

if ((minute > 9) && (minute < 15)) {

displayTEN();

displayPAST();

Serial.print("Ten Minutes ");

}

if ((minute > 14) && (minute < 20)) {

displayQUARTER();

displayPAST();

Serial.print("Quarter ");

}

if ((minute > 19) && (minute < 25)) {

displayTWENTY();

displayPAST();

Serial.print("Twenty Minutes ");

}

if ((minute > 24) && (minute < 30)) {

displayTWENTY();

displayFIVE();

displayPAST();

Serial.print("Twenty Five Minutes ");

}

if ((minute > 29) && (minute < 35)) {

displayHALF();

displayPAST();

Serial.print("Half ");

}

if ((minute > 34) && (minute < 40)) {

displayTWENTY();

displayFIVE();

displayTO();

Serial.print("Twenty Five Minutes ");

}

if ((minute > 39) && (minute < 45)) {

displayTWENTY();

displayTO();

Serial.print("Twenty Minutes ");

}

if ((minute > 44) && (minute < 50)) {

displayQUARTER();

displayTO();

Serial.print("Quarter ");

}

if ((minute > 49) && (minute < 55)) {

displayTEN();

displayTO();

Serial.print("Ten Minutes ");

}

if (minute > 54) {

displayFIVE();

displayTO();

Serial.print("Five Minutes ");

}

if (minute < 5) {

Serial.println(hour);

switch (hour) {

case 1:

displayONE();

break;

case 2:

displayTWO();

break;

case 3:

displayTHREE();

break;

case 4:

displayFOUR();

break;

case 5:

displayFIVE();

break;

case 6:

displaySIX();

break;

case 7:

displaySEVEN();

break;

case 8:

displayEIGHT();

break;

case 9:

displayNINE();

break;

case 10:

displayTEN();

break;

case 11:

displayELEVEN();

break;

case 12:

displayTWELVE();

break;

}

displayOCLOCK();

} else if ((minute < 35) && (minute > 4)) {

switch (hour) {

case 1:

displayONE();

break;

case 2:

displayTWO();

break;

case 3:

displayTHREE();

break;

case 4:

displayFOUR();

break;

case 5:

displayFIVE2();

break;

case 6:

displaySIX();

break;

case 7:

displaySEVEN();

break;

case 8:

displayEIGHT();

break;

case 9:

displayNINE();

break;

case 10:

displayTEN();

break;

case 11:

displayELEVEN();

break;

case 12:

displayTWELVE();

break;

}

} else {

switch (hour) {

case 1:

displayTWO();

break;

case 2:

displayTHREE();

break;

case 3:

displayFOUR();

break;

case 4:

displayFIVE2();

break;

case 5:

displaySIX();

break;

case 6:

displaySEVEN();

break;

case 7:

displayEIGHT();

break;

case 8:

displayNINE();

break;

case 9:

displayTEN();

break;

case 10:

displayELEVEN();

break;

case 11:

displayTWELVE();

break;

case 12:

displayONE();

break;

}

}

delay(60000);

long randNumber = random(720);

if (randNumber == 15) {

displayILVU();

delay(60000);

}

}

void testAll() {

int del = 200;

displayIT();

delay(del);

FastLED.clear();

displayIS();

delay(del);

FastLED.clear();

displayAM();

delay(del);

FastLED.clear();

displayPM();

delay(del);

FastLED.clear();

displayQUARTER();

delay(del);

FastLED.clear();

displayTWENTY();

delay(del);

FastLED.clear();

displayILVU();

delay(del);

FastLED.clear();

displayFIVE();

delay(del);

FastLED.clear();

displayHALF();

delay(del);

FastLED.clear();

displayTO();

delay(del);

FastLED.clear();

displayTEN();

delay(del);

FastLED.clear();

displayPAST();

delay(del);

FastLED.clear();

displayNINE();

delay(del);

FastLED.clear();

displayONE();

delay(del);

FastLED.clear();

displaySIX();

delay(del);

FastLED.clear();

displayTHREE();

delay(del);

FastLED.clear();

displayFOUR();

delay(del);

FastLED.clear();

displayFIVE2();

delay(del);

FastLED.clear();

displayTWO();

delay(del);

FastLED.clear();

displayEIGHT();

delay(del);

FastLED.clear();

displayELEVEN();

delay(del);

FastLED.clear();

displaySEVEN();

delay(del);

FastLED.clear();

displayTWELVE();

delay(del);

FastLED.clear();

displayTEN2();

delay(del);

FastLED.clear();

displayOCLOCK();

delay(del);

FastLED.clear();

}

void displayIT() {

for (int i = 108; i <= 109; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayIS() {

for (int i = 105; i <= 106; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayAM() {

for (int i = 101; i <= 102; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayPM() {

for (int i = 99; i <= 100; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayQUARTER() {

for (int i = 90; i <= 96; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayTWENTY() {

for (int i = 82; i <= 87; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayILVU() {

leds[70] = CRGB(0, 100, 80);

for (int i = 59; i <= 61; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayFIVE() {

for (int i = 78; i <= 81; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayHALF() {

for (int i = 66; i <= 69; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayTEN2() {

for (int i = 71; i <= 73; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayTO() {

for (int i = 75; i <= 76; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayPAST() {

for (int i = 62; i <= 65; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayNINE() {

for (int i = 55; i <= 58; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayONE() {

for (int i = 44; i <= 46; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displaySIX() {

for (int i = 47; i <= 49; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayTHREE() {

for (int i = 50; i <= 54; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayFOUR() {

for (int i = 40; i <= 43; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayFIVE2() {

for (int i = 36; i <= 39; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayTWO() {

for (int i = 33; i <= 35; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayEIGHT() {

for (int i = 22; i <= 26; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayELEVEN() {

for (int i = 27; i <= 32; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displaySEVEN() {

for (int i = 17; i <= 21; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayTWELVE() {

for (int i = 11; i <= 16; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayTEN() {

for (int i = 0; i <= 2; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

void displayOCLOCK() {

for (int i = 5; i <= 10; i++) {

leds[i] = CRGB(0, 100, 80);

}

FastLED.show();

}

It's commented right there. Change to the current time.

Actually, set it to a time just a little bit in the future, upload the code, and then wait for that time and power the board.

Then you need to comment the line back out and upload the code again, otherwise every time it starts it will set the time back to this time.

4 Likes

Thanks for replying!
Just gave it a go but it came up with this error. Can you please give me instructions on this problem? I think I understand that I haven't defined .adjust or DateTime but how can I define these? :')
Also do you know if this codes goes by American date format mm.dd.yyyy or dd.mm.yyyy?

/Users/abyoung/Documents/Arduino/wordclock/wordclock.ino: In function 'void setup()':
/Users/abyoung/Documents/Arduino/wordclock/wordclock.ino:24:5: error: 'class DS3231' has no member named 'adjust'
 rtc.adjust(DateTime(12,29,2023),(11,46,0)));
     ^~~~~~
/Users/abyoung/Documents/Arduino/wordclock/wordclock.ino:24:12: error: 'DateTime' was not declared in this scope
 rtc.adjust(DateTime(12,29,2023),(11,46,0)));
            ^~~~~~~~
/Users/abyoung/Documents/Arduino/wordclock/wordclock.ino:24:12: note: suggested alternative: 'Time'
 rtc.adjust(DateTime(12,29,2023),(11,46,0)));
            ^~~~~~~~
            Time
Multiple libraries were found for "DS3231.h"
  Used: /Users/abyoung/Documents/Arduino/libraries/DS3231
  Not used: /Users/abyoung/Documents/Arduino/libraries/DS3231_RTC
exit status 1

Compilation error: 'class DS3231' has no member named 'adjust'

That line doesn't look like the one that's commented in the original sketch. The one in the original sketch had no mention of DateTime.

Make one that looks like the one that's commented out in the original sketch.

1 Like

Here's some old code I dug up, that is for setting a DS3231 RTC.
You just have to type in the right numbers for year, month, etc.
So, for the year, you will use 0x23 for 2023, or 0x24 for 2024.
The month will be 0x12 for December, or 0x01 for January. And so forth.

#include "Wire.h"

void setup() {
  Wire.begin();
  Serial.begin(9600);
  // program to precisely set Chronodot
  Wire.beginTransmission(0x68); // address DS3231
  Wire.write(0x00); // select register
  
  Wire.write(0x30); // seconds (BCD)
  Wire.write(0x43); // minutes (BCD)
  Wire.write(0x17); // hours (BCD)
  Wire.write(0x07); // day of week (I use Mon=1 .. Sun=7)
  Wire.write(0x15); // day of month (BCD)
  Wire.write(0x09); // month (BCD)
  Wire.write(0x13); // year (BCD, two digits)
  
  Wire.endTransmission();
}

void loop() {
  delay(500);  
}

Thank you to both of you! idk what I did to the code after copying it but it worked :smiley:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.