Go Down

Topic: [Advice needed] Building a small BCD clock. (Read 3 times) previous topic - next topic

fungus

PPS: You could also do it with an ATtiny84 and a technique called "charlieplexing". It allows you to control (eg.) six LEDs with only three pins but it's tricky to get right.

See: https://en.wikipedia.org/wiki/Charlieplexing

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

marcuserronius

Using charleplexing, you can control up to 20 LEDs with 5 pins. This would be your best bet. I recently put some code up on Github that makes it relatively painless: https://github.com/marcuserronius/ChuckPlex/tree/1.0

… as for controlling the LEDs, I'd make arrays organizing the relevant LEDs. Split the time up into separate decimal components, and extract the extract the place values of the ON bits from each, use them as indices for the LEDs array, i.e.:
Code: [Select]

int digit1[] = {1,2};
int digit2[] = {3,4,5,6};
int digit3[] = {7,8,9};
int digit4[] = {10,11,12,13};
[…]
for(i=0;i<4;i++){
  if(bitRead(timeDigit2,i){
    // turn on LED digit2[i]
  }
}



Something like that, maybe. If you go with multiplexing the LEDs, this *might* end up causing too much flicker, in which case you could build a list of LEDs to turn on and cycle them until the next time the time changes.

ElectronicsNoobie

As you are building a BCD clock I would use an ATTiny with at least 8 outputs and arrange your leds on a 4x4 grid (with gaps where you dont need LEDs)

Then you can use 4 of your outputs for your rows and four for you columns and you have an easier solution than charlieplexing. You would need to row scan the rows of the 4x4 matrix but there are loads of tutorials on how to do that on these forums and on the net.

Something like
     X           X
     X      X   X
X  X      X   X
X  X      X   X
Hours   Minutes

HTH

Docedison

An RC oscillator isn't going to make a very accurate clock... Not at all. Go read the notes on RC frequency vs temperature and supply voltage variations. What you propose to do would be neat... as long as it didn't have to keep time.

Bob
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

iDroid

#9
Dec 19, 2012, 03:37 pm Last Edit: Dec 19, 2012, 03:52 pm by iDroid Reason: 1
Alright, hope this post isn't too old yet, because OP is here to deliver... Somewhat.

So I got this set up on a breadbord with the Arduino Uno, just to see how the code works. I'm using the millis() function to count milliseconds from the time when the program started. Every 1000 milliseconds, it adds one to seconds, every 60 seconds it adds one to minutes and so on. Each LED is connected to it's own digital pin on the Uno and lights up accordingly with basic if functions. Right now there's only one button to set minutes on digital pin 0, but I plan to add one for hours as well when its time to shrinkify this project to the ATtiny2313. The reference page says that this millis() function overflows after approximately 50 days, how badly does this affect the clocks accuracy?

I'm building the schematic with Eagle now. Do I need any other components, suchs as caps, in order for the ATtiny to work properly?

Thanks for your help guys!

EDIT: Will the buttons work with the ATtiny? I wired them (Or "it" at this time) as instructed on this page.

Go Up