I need assistance from code writer to complete sketch for a LED Clock. I am offering compensation for the effort. (Sketches were found online)
The sketch I would like to use is for a six digit display composed of seven segment modules, has LED to indicate PM (clock runs in 12 hour mode), but there is no code for setting the time. The sketch was originally written by coder 1 for a four digit display clock, blinking LED for seconds and two buttons to set the time.
When the sketch was modified by coder 2, the display was expanded to have digits for the seconds, the blinking led was repurposed to be a PM LED, but for some reason, the buttons were omitted. The RTC module was also changed from a DS3231 to DS1307. I would like to restore the buttons for time-setting. The buttons were assigned as 'Button 1 to set Hours, and Button 2 to set minutes. They only counted forward one digit per button press, but the minute button seemed to reset the seconds count to zero each time it was pressed. I liked that because it made it easier to synchronize the time to another clock.
The original sketch I found is posted here...
#include "SevSeg.h"
#include <DS3231.h>
DS3231 rtc(SDA, SCL);
Time t;
SevSeg Display;
const int hrs_set = A0;
const int min_set = A1;
const int ledPin = A3;
unsigned int number = 0;
const long interval = 500;
unsigned long startMillis;
unsigned long currentMillis;
unsigned long previousMillis = 0;
unsigned int Hour = 0;
unsigned int hrs_var = 0;
unsigned int min_var = 0;
int ledState = HIGH;
void setup()
{
rtc.begin();
pinMode(ledPin, OUTPUT);
pinMode(hrs_set, INPUT_PULLUP);
pinMode(min_set, INPUT_PULLUP);
byte numDigits = 4;
byte digitPins[] = {10, 11, 12, 13};
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8};
bool resistorsOnSegments = false;
bool updateWithDelays = false;
byte hardwareConfig = COMMON_ANODE;
bool leadingZeros = false;
bool disableDecPoint = true;
Display.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, disableDecPoint);
Display.setBrightness(60);
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
previousMillis = currentMillis;
if (ledState == HIGH)
{
ledState = LOW;
}
else
{
ledState = HIGH;
}
digitalWrite(ledPin, ledState);
}
t = rtc.getTime();
Hour = t.hour;
hrs_var = t.hour;
min_var = t.min;
if (t.hour > 12)
{
if (t.hour == 13) Hour = 1;
if (t.hour == 14) Hour = 2;
if (t.hour == 15) Hour = 3;
if (t.hour == 16) Hour = 4;
if (t.hour == 17) Hour = 5;
if (t.hour == 18) Hour = 6;
if (t.hour == 19) Hour = 7;
if (t.hour == 20) Hour = 8;
if (t.hour == 21) Hour = 9;
if (t.hour == 22) Hour = 10;
if (t.hour == 23) Hour = 11;
}
else
{
if (t.hour == 0) Hour = 12;
}
number = Hour * 100 + t.min;
Display.setNumber(number);
Display.refreshDisplay();
if (digitalRead(hrs_set) == HIGH)
{
hrs_var += 1;
if (hrs_var > 23) hrs_var = 0;
rtc.setTime(hrs_var, min_var, 0);
for (int i = 0; i < 1000; i ++)
{
Display.setNumber(number);
Display.refreshDisplay();
}
}
if (digitalRead(min_set) == HIGH)
{
min_var += 1;
if (min_var >= 60) min_var = 0;
rtc.setTime(hrs_var, min_var, 0);
for (int i = 0; i < 1000; i ++)
{
Display.setNumber(number);
Display.refreshDisplay();
}
}
}
and here is the modified code...
#include "SevSeg.h"
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
SevSeg Display;
// const int hrs_set = A0; /hour setting button
// const int min_set = A1; /minute setting button
const int ledPin = A3;
unsigned long timeDisplay;
unsigned long currentMillis;
unsigned int Hour;
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 500;
void setup()
{
pinMode(ledPin, OUTPUT);
byte numDigits = 6;
byte digitPins[] = {9, 10, 11, 12, 13, A2};
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8};
bool resistorsOnSegments = false; // false = resistors are on digit pins
bool updateWithDelaysIn = true;
byte hardwareConfig = COMMON_ANODE;
Display.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
Display.setBrightness(60);
}
void loop()
{
tmElements_t tm;
if (RTC.read(tm))
{
Hour = tm.Hour;
if (tm.Hour >= 12)
{
if (tm.Hour == 13) Hour = 1;
if (tm.Hour == 14) Hour = 2;
if (tm.Hour == 15) Hour = 3;
if (tm.Hour == 16) Hour = 4;
if (tm.Hour == 17) Hour = 5;
if (tm.Hour == 18) Hour = 6;
if (tm.Hour == 19) Hour = 7;
if (tm.Hour == 20) Hour = 8;
if (tm.Hour == 21) Hour = 9;
if (tm.Hour == 22) Hour = 10;
if (tm.Hour == 23) Hour = 11;
ledState = HIGH; // PM
}
else
{
if (tm.Hour == 0) Hour = 12;
ledState = LOW; // AM
}
digitalWrite(ledPin, ledState);
timeDisplay = (Hour * 100 + tm.Minute) * 100L + tm.Second;
}
else
{
timeDisplay = 888888; // error
}
Display.setNumber(timeDisplay);
Display.refreshDisplay();
}
Since the two sketches used different RTC modules, I couldn't figure out how to change the time-setting code in the first sketch to add to the second sketch. I also have the wiring diagram for the original clock shown here...
and the diagram for the clock I wish to complete...
This is a one-time project involving Arduino, and any help would be greatly appreciated.