Hello everyone,
So I have been programming the Arduino for enchanted clock I'm building (Work in progress). I am still having issues with the SAMA5D4 Xplained, I may have to change to an RPi if time starts to get tight. I really don't want to do this as our sponsors have been very generous and I don't want to let them down.
So to update where I am at. I have decided that for the clock to stay in time due to the inconsistency in a wood clock, I have made a binary clock. This clock will be integrated with my wood clock and through servos it will re-set it to the correct time. Below is a picture of the Binary Clock on the breadboard working. I will make a PCB board cape for final product. The time on the Binary Clock will be seen as well as the wood clock time.
Schematic:
Clock Code:
#include <Wire.h>
#include <RTClib.h>
#include <TimerOne.h>
byte numPins = 5;
byte ledPins[] = {2, 5, 8, 10, 12};
byte hourLeds[][2] = {{1, 3}, {3, 1}, {0, 3}, {3, 0}};
byte minLeds[][2] = {{4, 2}, {3, 4}, {2, 3}, {1, 2}, {0, 1}, {2, 0}};
byte secLeds[][2] = {{2, 4}, {4, 3}, {3, 2}, {2, 1}, {1, 0}, {0, 2}};
RTC_DS1307 RTC;
int hour, min, sec;
void setup()
{
Wire.begin();
if (! RTC.isrunning())
{
RTC.adjust(DateTime(__DATE__, __TIME__));
}
Timer1.initialize(20000); // uS
Timer1.attachInterrupt( refresh );
}
void loop()
{
static long lastTick;
long thisTick = millis();
if (thisTick > lastTick + 500l) // every 0.5 seconds
{
DateTime now = RTC.now();
hour = now.hour();
min = now.minute();
sec = now.second();
lastTick = thisTick;
}
refresh();
}
void refresh()
{
int s = sec;
int m = min;
int h = hour;
for (int bit = 0; bit < 6; bit++)
{
if (s & 1)
{
setLed(secLeds[bit]);
// delay(10);
}
s = s >> 1;
if (m & 1)
{
setLed(minLeds[bit]);
}
m = m >> 1;
if (h & 1 && bit < 4)
{
setLed(hourLeds[bit]);
}
h = h >> 1;
}
allOff(); // so last led not brighter
}
void setLed(byte pins[])
{
byte plusPin = ledPins[pins[0]];
byte minusPin = ledPins[pins[1]];
allOff();
pinMode(plusPin, OUTPUT);
digitalWrite(plusPin, HIGH);
pinMode(minusPin, OUTPUT);
digitalWrite(plusPin, LOW);
}
void allOff()
{
for (byte pin = 0; pin < numPins; pin++)
{
pinMode(ledPins[pin], INPUT);
}
}
Servo controller and timing sensor to be programmed into the script, this is for the clock only (so far).
My big focus is on the wooden clock, this is a huge part in the whole project. I will update mid week with photos of the progress.
Dale & Chrystal Winhold
Top Comments