Hey guys,
I am working on a rather hefty project for a gift. It is an "analog" clock that is powered by Arduino UNO R2. I have a lot of aspects that will need guidance as this is my first project with Arduino. I have done other circuit modules before when I was in electrical engineering I know some coding (Mainly MatLab code), but am relatively new to C. I have a good understanding of the logic however. Anyways Here is a picture of the prototype drawing. everything that is black is going to be backlit with LED's. There will be minute and hour hands powered by a stepper motor. There will also be a 7-segment display at the bottom (not shown).
Now here is where I need guidance. there are a lot of features I want to design for this clock. I will list them out
- I want each second tick-mark to blink for the second and fading out, leading up to the tick-mark. lets say the backlit brightness is 10% of the set max. when it blinks, it will go to 100% and fade back to 10%.
- Using the same percent brightness scale, I want the numbers 1-12 to have a slow fade based on where the hour hand is: if its on 1, the 1 will light to 100%. if its on 2, the 2 will light at 100% and the 1 will be back at 10%. if its at 1:30, both the 1 and the 2 will be at 10+(100-10)/2 = 55%. if its at 1:10, the 1 will light at 10+(100-10)(5/6)=85% and the 2 will light at 10+(100-10)(1/6)=25% (formula is min + (max - min)*(minutes/60) This won't be too hard I don't think, but that remains to be seen.
- I want the hands to automatically go to the correct time when powered on from the wall plug. As I understand, I can keep the time on the arduino board, and plan on using a sensor of some sort to set the hands to a "home" position, and then rotate to the correct time. Also, these hands will be made of acrylic and have another LED shone trough them. I'm not concerned about that right now.
- Lastly, every hour on the hour, I want the whole clock that is backlit to glow and fade the number of times that the hour shows. so for 3:00, itll blink/glow 3 times. This isn't as important, but I thought it'd be cool.
Ok so that's a hefty list of features. I didn't even go into the gearing of the hands or how to get them to light up. Right now I'm focused more on the other lighting and coding. I know this list is too big to cover at the same time, so I have a few questions and want to focus on the first point only for right now.
Ok so first feasibility question: I want this clock to be accurate for a long time, years if possible. I know I'll be able to code everything I want independently: I am concerned for the time it takes to do loops and whatnot however, and how it will deviate from true time. I saw that Arduino keeps time on the board: is there a way to code a reset button for the lights and hands at the end of the day for instance to recall the true time, and adjust accordingly? If not, are there any general guidelines to keep computational time to a minimum?
Next, I have made a code for fading of the second lights already here:
*
6 LED clock
this code does a blink and fade for 6 LED's per second in order.
*/
int led3 = 3; // the pin that the LED is attached to
int led5 = 5;
int led6 = 6;
int led9 = 9;
int led10 = 10;
int led11 = 11;
int brightness = 255; // how bright the LED is
int loopbrightness = 255; // initial brightness value for the loops
int fadeAmount = 5; // how many points to fade the LED by
void setup() {
// initialize the digital pin as an output.
pinMode(led3, OUTPUT);
analogWrite(led3, 10);
pinMode(led5, OUTPUT);
analogWrite(led5, 10);
pinMode(led6, OUTPUT);
analogWrite(led6, 10);
pinMode(led9, OUTPUT);
analogWrite(led9, 10);
pinMode(led10, OUTPUT);
analogWrite(led10, 10);
pinMode(led11, OUTPUT);
analogWrite(led11, 10);
}
void loop() {
{loopbrightness = brightness; //starts at 255
do {
analogWrite(led3, loopbrightness); // turn the LED on, starting at 255)
loopbrightness = loopbrightness - fadeAmount; //decreases the brightness by 5
delay(15); // each step takes .015 seconds: there are (255-10)/5 = 49 iterations, for a total of .735 seconds, with an extra .015 added at the end.
}while(loopbrightness > 5); } //breaks when loopbrightness <=5. the ending written loopbrightness is 10, and .015 seconds is delayed after the subtraction, as stated above.
delay(250); //finish off the remaining time in a second: 1-.735-.015 = .250
{loopbrightness = brightness; //second LED
do {
analogWrite(led5, loopbrightness);
loopbrightness = loopbrightness - fadeAmount;
delay(15);
}while(loopbrightness > 5); }
delay(250);
{loopbrightness = brightness; //third LED
do {
analogWrite(led6, loopbrightness);
loopbrightness = loopbrightness - fadeAmount;
delay(15);
}while(loopbrightness > 5); }
delay(250);
{loopbrightness = brightness; //fourth LED
do {
analogWrite(led9, loopbrightness);
loopbrightness = loopbrightness - fadeAmount;
delay(15);
}while(loopbrightness > 5); }
delay(250);
{loopbrightness = brightness; //fifth LED
do {
analogWrite(led10, loopbrightness);
loopbrightness = loopbrightness - fadeAmount;
delay(15);
}while(loopbrightness > 5); }
delay(250);
{loopbrightness = brightness; //sixth LED
do {
analogWrite(led11, loopbrightness);
loopbrightness = loopbrightness - fadeAmount;
delay(15);
}while(loopbrightness > 5); }
delay(250);
}
This works with only 6 LEDs since the board I am working on only has 6 digital pins that can do analog. I was suggested that to do all 60 seconds, I could use the serial ports on the board to an LED driver or multiplexer or something. I have this driver IC that I thought might work, but with my fade effect, I think this only does a digital output, not an analog signal that I need. Does anyone have ideas for this? I considered getting a bigger Arduino, but I want to see if I can make this work first.
Lastly for now, along the same lines, the circuit I made earlier tonight has all LEDs hooked up to power with 2 resistors that go 680 ohm to 330 ohm to LED to ground. here is a picture:
For the blink fading effect I want, I thought I could send the signal from the arduino between the resistors and work: but when I power the Arduino, the LED goes dark and I have to set a minimum brightness (reflected in the code). Any other ideas for the circuit? should I stay with the idea of all the LEDs connected to ground, and sending a signal that will make individual ones brighter? or try something altogether different?
Edit: could I possibly do the fade effect with capacitors, and not even worry about analog signals, using only digital signals? This might solve so many of my problems.
Anyways lots of questions, I know this is a lot. Thanks for reading the wall of text and your replies. I appreciate them.