Problems combining crossfade with moving LEDs on strip (both controlled by RTC)


I’m new to programming and this is my first post on this forum, so please forgive me in advance for any incorrect terminology I use.

I’m in the process of making a sunrise clock using an LED strip which replicates a sundial. A group of 6 LEDs move along the strip (attached to a circular casing) to act as the sun, and their position is controlled by a time value from a RTC. I would like the LED group to change colour depending on the time of day (ie. for sunrise and sunset).

At the moment I have two independent pieces of code that work with no problems; one to control the position of the group (time depedent) and, the other to control the colour of the LEDs in a Crossfade function (also time dependent).

In my main code, I am using the Timelord.h library to calculate sunrise and sunset times for the crossfade function, but to keep this question short I’ve just referenced the specific RTC times.

I’ve got most of my code from adapting bits I’ve found online, so there may be minor ‘grammer’ errors here and there.

The kit I’m using is as follows:
Arduino Uno board,
RTC DS1307
RGB LED Strip WS2812B

I’ve attached both codes to this post as I exceeded the 9000 character limit, so you can find them below.

What I would like to do is call the crossfade code inside the positioning code, as I would like all 6 moving LEDs to have the same colour which crossfades.

Is there a way to call the crossfade if loops within strip.setPixelColor(i, HEXCOLOR)?

Thank you in advance for any help or advice you can give me!

Crossfade.ino (7.09 KB)

Moving_LEDs.ino (2.54 KB)

For merging code see:-Merging Code

However it is likely that you want to eliminate all uses of the delay function, this requires a different programming technique, see
Or Robin2's several things at once

Thanks for pointing me in the right direction! I'll read those links and hopefully come up with something :slight_smile: