Hello world. Right i have been slowly teaching my self through different projects and have hit a bit of a mental break down on the best way to achieve what i want from my project.
I am building a Binary clock using an atmega328p on a breadboard for now, then the hope is to move it forward to a full working pocket watch once i am happy with the prototype.
Now the problem is power consumption of the LEDS and the watch lasting for a reasonable time.
I Know this can be done by making the 328 carry on counting time but to switch off the LEDS say 30 seconds after a switch is activated like a push button or when i open the watch case.
Now my problem is with the best way to go about this with out using 'if' statements too much and slowing the clock down and losing time.
This is the code so far.... and any suggestions would be more than appreciated in solving my problem and even if code is the right way to do this and if not maybe a better hardware solution is out there?
// CSM
// binary clock code V1.2, on atmega328p-pu breadboard.
#include <Time.h> // Using the basic Time library
int hourLEDs[] = {1, 2, 3, 4}; // Hours LED
int minuteLEDs[] = {10, 9, 8, 7, 6, 5}; // Minutes LED
int secondLEDs[] = {16, 15, 14, 13, 12, 11}; // Seconds LED
int loopLEDs[] = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; // The order in which to spin the LEDS
int switchPin = 17 ; // Used for setting the time, hold to advance time
void setup()
{
for (int i = 0; i < 4; i++)
{
pinMode(hourLEDs[i], OUTPUT);
}
for (int i = 0; i < 6; i++)
{
pinMode(minuteLEDs[i], OUTPUT);
}
for (int i = 0; i < 6; i++)
{
pinMode(secondLEDs[i], OUTPUT);
}
setTime(0);
}
void loop()
{
if (digitalRead(switchPin))
{
adjustTime(1);
}
else if (minute() == 0 && second() == 0)
{
spin(hour());
}
updateDisplay();
delay(1);
}
void updateDisplay()
{
time_t t = now();
setOutput(hourLEDs, 4, hourFormat12(t));
setOutput(minuteLEDs, 6, minute(t));
setOutput(secondLEDs, 6, second(t));
}
void setOutput(int *ledArray, int numLEDs, int value)
{
for (int i = 0; i < numLEDs; i++)
{
digitalWrite(ledArray[i], bitRead(value, i));
}
}
void spin(int count)
{
for (int i = 0; i < count; i++)
{
for (int j = 0; j < 16; j++)
{
digitalWrite(loopLEDs[j], HIGH);
delay(50);
digitalWrite(loopLEDs[j], LOW);
}
}
}
Many Thanks