Help with LED clock

Sorry folks, I shall admit I have spent MANY hours recently trying to get this working.

(Back story)
It worked, but each year (twice) it would fail when the clocks were adjusted for daylight saving time.
After a bit of work, I realised I could cheat and keep the clock on the same time and just add an hour if the DLS flag is set.

Easy.

Then I went on to adjust the brightness in the evening from "full" to dim, to dimmer to dark.
(Same kind of things in the morning.)

There are two options for morning/evening dimming.
0 - use the set times.
1 - dim depending on Sunrise/set time.

It is looking good, but has caught me out a few times.

"Today" I spent about 4 hours (solid) trying to get it working, and it looked like it did.
But when I unplugged it from the PC, and plugged it back into it's power supply the time was wrong.
When I plugged it back into the computer (hours later after realising the error) and as soon as I plugged it back into the PC, the time was correct.

Put it back in the power supply. All good.
Hmmm....

Another few hours on, I look and the hour indicator (which was right) was/had gone backwards!
Again, powered up PC, plugged in to the PC USB port, and when it powered up - again - it was showing the right time.

There is a RTC chip and when I open the "DEBUG" window it is showing the right time.

I set the time to 59 minutes and waited for the hour to tick over.
It worked. No problems.
(Of course. Sod's law. I was watching.)

I have combined all the tabs into one to make it easier for all parties.

Libraries used:

#include <DS3232RTC.h>        //http://github.com/JChristensen/DS3232RTC
#include <Time.h>             //http://playground.arduino.cc/Code/Time
#include <Wire.h>             //http://arduino.cc/en/Reference/Wire
#include <Streaming.h>        //http://arduiniana.org/libraries/streaming/
#include <EEPROM.h>

#include <stdio.h>
#include <Adafruit_NeoPixel.h>

(Not included)

Ring_Clock15f.zip (13.4 KB)

BRIGHT_CONTROL and DARK_CONTROL are the settings to control how the morning and evening display is adjusted.

I am sorry the code is not the best.
It started a few years back and this is the most recent version.

The quest I am asking:

I have not (yet) tested the evening dimming of the LED strip.
(Nor the morning one)

I've done my best to list the routines (see line 40 onward) for naming the order they are in the code.

Line 244 onward explains what is used for the brightness of the LED loop.

Problem I've seen:

The hour hand goes backward - when the hour changes I think.
It was set, it was near the end of the hour. A fair time later I looked at the clock and the hour hand was no longer correct.
It had gone backwards from (say) "4" to "2".
There was/were no power interruptions while this happened.

Things I would like checked:

See if the logic is working for the getRiseSet routine is adjusting the times when the LED loop is dimmed (brightness is adjusted).

Apologies for:

There is probably a lot of either duplicated or not used routines.
This is because I dragged example codes (from the libraries used) and merged them into the code.
There is also stuff for printing out the time on the serial port.
Not really needed for most of the time but is needed/used when I am debugging the code.

Example of output to serial port:

Version 15f
Setting up
  Enter time in line to set if wrong.
  Format:  yy,mm,dd,hh,mm,ss,dow, 
RTC time is (This is NOT allowing for DLS!)
2023/10/6 16:46:2 DLS 1
Sunrise/Set calc
*******************************
*******************************
Using Fixed time
Using Sunset time
Sunrise time = 5:0
Sunset time = 19:26
-------------------------------
Morning start time = 5:0
Day start time = 5:30
-------------------------------
Evening start time = 19:30
Night start time = 20:45
-------------------------------
Bed start time = 22:20
-------------------------------
Minutes past Midnight 1066
-------------------------------
       mpm values below.
mpm 1066
SRmpm 300
SSmpm 1166
Mmpm 300
Dmpm 330
EVmpm 1170
Nmpm 1245
Bmpm 1340
-------------------------------
Done setting up
===============================
*******************************
===============================
Date 06Oct2023 16:46:02 
---------------------------------------------------------------------------
17:46:02  - day 6 -  06/10/2023  temp: 0.00 DLS flag: 1 Alarm Flag 0 O/E 0
===========================================================================
Brightnes set to 255
---------------------------------------------------------------------------
17:46:03  - day 6 -  06/10/2023  temp: 0.00 DLS flag: 1 Alarm Flag 0 O/E 0
===========================================================================
Date 06Oct2023 16:46:03 
---------------------------------------------------------------------------
17:46:04  - day 6 -  06/10/2023  temp: 0.00 DLS flag: 1 Alarm Flag 0 O/E 1
===========================================================================
Date 06Oct2023 16:46:04 
---------------------------------------------------------------------------
17:46:05  - day 6 -  06/10/2023  temp: 0.00 DLS flag: 1 Alarm Flag 0 O/E 0
===========================================================================

mpm = minutes past midnight.
Handy for determining what to do at that time of the day.
A lot of variations on it as you can see.
SRmpm - sunrise
SSmpm - sunset
Mmpm - morning time when I want the display to become visible (mildly bright)
Dmpm - when I want the display to become brightest
EVmpm - evening when I want to dim the display
Npmp - night dim the display to a dimmer level - but still visible
Bmpm - basically when I don't need/want the display to really display anything. When I am bed. Thus the name.

Again,
I am sorry for seeming dumping this on you.
I have spent a lot of time trying to get it working but am making mistake after mistake and though I don't mind a challenge: this seems to be beyond me for some parts.
Thus you will see a lot of commented out code.
I leave it there for a while so if I am trying new code, I know not to do it that way again.
Or it is I am trying something and not sure the new way will work, so leave the old code there so if it doesn't work, I can easily go back to the previous way.

Thanks in advance.

1 Like

you get a like because you are literally the first this month describing which libraries he is using.

extract the function to a separate test sketch,
feed it with all possible data (for example with for loops)
check the result in Serial.

and not related to your problem but

  • if you are on a small Arduino UNO/NANO... read about the F-Makro and use it.
  • as you are already using Streaming.h in some places, clean up your code and use it more consistently. You can spare a lot of lines of code, less code --> less risk to get confused.
1 Like

Thanks.

Only mentioning this as I am replying and it just happened again.
(local time just changed the hour - well, ok 28 minutes ago)

It was 18:59 and.....

19:00

The clock showed 18:00

Powered down and plugged into computer's USB port.

Clock now showing 19:00.... NO ADJUSTMENTS DONE BY ME
Only a power cycle - basically.

As said: I set the time to Hour:59:50 and watched it go through the last 10 seconds of the hour.

It worked - of course.

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