after extensive serches on the internet, i ran across an article discussing the use of the MAP function and applied it to the code. now the clock works like a charm. he is what i did.
#include <FastLED.h>
#include <Wire.h>
#include <RTClib.h>
#include <EEPROM.h>
#include <Encoder.h>
DS3231 RTC;
#define DATA_PIN 6 //for 2 wire LED strips
#define CLOCK_PIN 5
//#define LEDStripPin 8 //for single wire LED strips
#define numLEDs 60 //number of LEDs in the strip
//Setting up the LED strip
struct CRGB leds[numLEDs];
Encoder rotary1(10, 11); //setting up the Rotary Encoder
DateTime old; //Variable to compare new and old time, to see if it has moved on
int rotary1Pos = 0;
int subSeconds; //60th's of a second
long newSecTime; //Variable to record when a new second starts, allowing to create milli seconds
long oldSecTime;
#define clockState 0
int cyclesPerSec;
float cyclesPerSecFloat; // So can be used as a float in calcs
float fracOfSec;
int timeHour;
int timeMin;
int timeSec;
int modeAddress = 0; // Address of where mode is stored in the EEPROM
long currentMillis;
long previousMillis = 0;
int state = 0;
int mode; // Variable of the display mode of the clock
int modeMax = 3; // Change this when new modes are added. This is so selecting modes can go back beyond.
int advanceMove = 0;
long lastRotary;
int rotaryTime = 1000;
int LEDPosition;
int fiveMins;
int LEDOffset = 30;
void setup()
{
// Set up all pins
// pinMode(menuPin, INPUT_PULLUP); // Uses the internal 20k pull up resistor. Pre Arduino_v.1.0.1 need to be "digitalWrite(menuPin,HIGH);pinMode(menuPin,INPUT);"
// Start LEDs
// LEDS.addLeds<WS2811, LEDStripPin, GRB>(leds, numLEDs); // Structure of the LED data. I have changed to from rgb to grb, as using an alternative LED strip. Test & change these if you're getting different colours.
LEDS.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR>(leds, numLEDs);
// Start RTC
Wire.begin(); // Starts the Wire library allows I2C communication to the Real Time Clock
RTC.begin(); // Starts communications to the RTC
Serial.begin(9600); // Starts the serial communications
// Uncomment to reset all the EEPROM addresses. You will have to comment again and reload, otherwise it will not save anything each time power is cycled
// write a 0 to all 512 bytes of the EEPROM
// for (int i = 0; i < 512; i++)
// {EEPROM.write(i, 0);}
// Load any saved setting since power off, such as mode & alarm time
mode = EEPROM.read(modeAddress); // The mode will be stored in the address "0" of the EEPROM
}
void loop()
{
DateTime now = RTC.now(); // Fetches the time from RTC
rotary1Pos = rotary1.read(); // Checks the rotary position
if (rotary1Pos <= -4 && lastRotary - millis() >= rotaryTime)
{
advanceMove = -1;
rotary1.write(0);
lastRotary = millis();
}
if (rotary1Pos >= 4 && lastRotary - millis() >= rotaryTime)
{
advanceMove = 1;
rotary1.write(0);
lastRotary = millis();
}
{
switch (mode)
case clockState: // State 0
if (advanceMove == -1 && mode == 0)
{
mode = modeMax;
advanceMove = 0;
}
else (advanceMove != 0);
{
mode = mode + advanceMove;
EEPROM.write(modeAddress, mode);
advanceMove = 0;
}
}
{
timeDisplay(now);
}
// Update LEDs;
LEDS.show();
memset(leds, 0, numLEDs * 3);
}
void clearLEDS()
{
for (int i = 0; i < numLEDs; i++) // set all LEDs to off
{
leds[i].r = 0;
leds[i].g = 0;
leds[i].b = 0;
}
}
void timeDisplay(DateTime now)
{
switch (mode)
{
case 0:
outlineClock(now);
break;
case 1:
outlineDSTClock(now);
break;
case 2:
minimalClock(now);
break;
case 3:
minimalDSTClock(now);
break;
default: // Keep this here and add more timeDisplay modes as defined cases.
{
mode = 0;
}
}
}
void outlineClock(DateTime now)
{
// for (int i = 59; i >= 0 ; i--)
for (int i = 0; i < numLEDs; i++)
{
fiveMins = i % 5;
if (fiveMins == 0)
{
leds[i].r = 2;
leds[i].g = 2;
leds[i].b = 2;
}
}
if (now.second() != old.second())
{
old = now;
}
// set hour, min & sec LEDs
/*
//uncomment this section to use with rings that are constructed clockwise
unsigned char hourPos = ((now.hour() % 12) * 5 + (now.minute() + 6) / 12);
leds[(hourPos + LEDOffset + 59) % 60].r = 5;
leds[(hourPos + LEDOffset) % 60].r = 20;
leds[(hourPos + LEDOffset + 1) % 60].r = 5;
leds[(now.minute() + LEDOffset) % 60].g = 20;
leds[(now.second() + LEDOffset) % 60].b = 30;
*/
// uncomment this section to use rings that are constructed counter clockwise (Lumini 3" APA102 2020)
unsigned char hourPos = ((now.hour() % 12) * 5 + (now.minute() + 6) / 12);
unsigned char minPos = (now.minute());
unsigned char secPos = (now.second());
int valh = hourPos;
int valm = minPos;
int vals = secPos;
int hours = map(valh, 0, 59, 59, 0);
int mins = map(valm, 0, 59, 59, 0);
int secs = map(vals, 0, 59, 59, 0);
leds[(hours + LEDOffset + 7) % 60].r = 2;
leds[(hours + LEDOffset + 6) % 60].r = 20;
leds[(hours + LEDOffset + 5) % 60].r = 2;
leds[(mins + LEDOffset + 1) % 60].g = 20;
leds[(secs + LEDOffset + 1) % 60].b = 30;
}
void outlineDSTClock(DateTime now)
{
//for (int i = numLEDs - 1; i > -1; i--)
for (int i = 0; i < numLEDs; i++)
{
fiveMins = i % 5;
if (fiveMins == 0)
{
leds[i].r = 2;
leds[i].g = 2;
leds[i].b = 2;
}
}
if (now.second() != old.second())
{
old = now;
}
// set hour, min & sec LEDs
/*
//uncomment this section to use with rings that are constructed clockwise
unsigned char hourPos = ((now.hour() % 12) * 5 + (now.minute() + 6) / 12);
leds[(hourPos + LEDOffset + 54) % 60].r = 10;
leds[(hourPos + LEDOffset + 55) % 60].r = 20;
leds[(hourPos + LEDOffset + 56) % 60].r = 10;
leds[(now.minute() + LEDOffset) % 60].g = 20;
leds[(now.second() + LEDOffset) % 60].b = 20;
*/
// uncomment this section to use rings that are constructed counter clockwise (Lumini 3" APA102 2020)
unsigned char hourPos = ((now.hour() % 12) * 5 + (now.minute() + 6) / 12);
unsigned char minPos = (now.minute());
unsigned char secPos = (now.second());
int valh = hourPos;
int valm = minPos;
int vals = secPos;
int hours = map(valh, 0, 59, 59, 0);
int mins = map(valm, 0, 59, 59, 0);
int secs = map(vals, 0, 59, 59, 0);
leds[(hours + LEDOffset + 2) % 60].r = 2;
leds[(hours + LEDOffset + 1) % 60].r = 20;
leds[(hours + LEDOffset) % 60].r = 2;
leds[(mins + LEDOffset + 1) % 60].g = 20;
leds[(secs + LEDOffset + 1) % 60].b = 30;
}
void minimalClock(DateTime now)
{
/*uncomment this section to use with rings that are constructed clockwise
unsigned char hourPos = (now.hour() % 12) * 5;
leds[(hourPos + LEDOffset) % 60].r = 10;
leds[(now.minute() + LEDOffset) % 60].g = 10;
leds[(now.second() + LEDOffset) % 60].b = 10;
*/
// uncomment this section to use rings that are constructed counter clockwise (Lumini 3" APA102 2020)
unsigned char hourPos = ((now.hour() % 12) * 5 + (now.minute() + 6) / 12);
unsigned char minPos = (now.minute());
unsigned char secPos = (now.second());
int valh = hourPos;
int valm = minPos;
int vals = secPos;
int hours = map(valh, 0, 59, 59, 0);
int mins = map(valm, 0, 59, 59, 0);
int secs = map(vals, 0, 59, 59, 0);
leds[(hours + LEDOffset +6) % 60].r = 10;
leds[(mins + LEDOffset + 1) % 60].g = 10;
leds[(secs + LEDOffset + 1) % 60].b = 10;
}
//
void minimalDSTClock(DateTime now)
{
/*uncomment this section to use with rings that are constructed clockwise
unsigned char hourPos = (now.hour() % 12) * 5 + (now.minute() + 6) / 12);
leds[(hourPos + LEDOffset + 55) % 60].r = 10;
leds[(now.minute() + LEDOffset) % 60].g = 10;
leds[(now.second() + LEDOffset) % 60].b = 10;
*/
// uncomment this section to use rings that are constructed counter clockwise (Lumini 3" APA102 2020)
unsigned char hourPos = ((now.hour() % 12) * 5 + (now.minute() + 6) / 12);
unsigned char minPos = (now.minute());
unsigned char secPos = (now.second());
int valh = hourPos;
int valm = minPos;
int vals = secPos;
int hours = map(valh, 0, 59, 59, 0);
int mins = map(valm, 0, 59, 59, 0);
int secs = map(vals, 0, 59, 59, 0);
leds[(hours + LEDOffset + 1) % 60].r = 10;
leds[(mins + LEDOffset + 1) % 60].g = 10;
leds[(secs + LEDOffset + 1) % 60].b = 10;
}