Go Down

Topic: DIGITAL CLOCK (Read 654 times) previous topic - next topic

shanecy

Feb 11, 2013, 08:59 pm Last Edit: Feb 11, 2013, 09:27 pm by CrossRoads Reason: 1
Due to difficulty on opening up the word documents, i've posted, I'm going to put the projects details and my questions here below. Hope this works.

Please disregard the file titled "Project_Questions" as the below information is what it contains.

The other files contain the specifics that may help understand my project and specifications of my parts.

INTRODUCTION:

Two of us are Electronic and Computer Engineering students here in Colorado. We have a basic understanding of C++ and C programming due to completing COMP 120. We are still early students in our program but have been working ahead to enhance our skills and understanding. Therefore, our design and code may seem very rough, as you will see.  We want to approach this project solely on the knowledge that we have instead of just copying other people's code and design. We have agreed this is the best way to learn as we progress through our project.

PROJECT:

We want to build a Digital Clock that will be displayed on multiple LED displays (Hours, Minutes, Seconds). Eventually we would like to incorporate a button to actual set the time and or reset but for now we want to keep it simple

COMPONENTS LIST (ITEMS):

2-Single Digit Display LEDs (Model#:ELS-321HDB)

1-Arduino micro-controller (Model: UNO)

1-Standard Breadboard

Arduino Programming Interface (Version 1.0.3)

Environment (OSX Version 10.8.2) MacBook (Flash Drive Tech)

1-10K ohm resistor (Used at the moment to regulate current through the Display "I don't want to blow out my display")

CURRENT STATUS:

As of right now I want to focus my attention on building a counter. I've made my code based on what I could think up of at the time. My code is very basic but I've built it on my own without copying another person's idea. I realize that I will need to add many functions and commands to my code for the real thing. Therefore, the current code attached is only for my counter. I've hooked up some LED displays by following the specifications of this model.

QUESTIONS:

I really want to incorporate a more efficient code for this counter. I need some help with your perspective on how I could make it more efficient. Could I use a "for loop"? There also may be things I'm not taking into consideration here when building a simple counter. If I'm not taking something into consideration could you please suggest these?

Also after I make my code more efficient I need a perspective on how I'm going to design my code for the real thing. There probably will exist several changes and functions/commands I will need to introduce. I need some help here as coding comes hard to me and I don't always see the multiple ways I can go about doing something.

ADDITIONAL NOTES:

I want to stress the idea here that at the moment I just wanted to figure out how to design a counter with a simple LED display and a simple code. There are multiple ways I'm sure I could of done this but this is the way that I could only make sense in doing.

Also I realize that my finished code for the actual digital clock will need to be much more complex and will include more functions and commands. So right now I just want to come more familiar with Arduino programming so later I can have a perspective of how my code is going to look for the real thing.

I attached some documents. These documents include a picture of what I've built so far for a description and a specifications sheet for the LED displays. I've commented on my source code so I think it's very explanatory for when your going through it.


Here is my code that i've build for the counter. I was going to attach a word document containing my code but there was some problems. Therefore, I hope this helps.
Code: [Select]

//Programmer:  Shane Yost
//Project:     Digital Clock
//Date:        Feburary 10, 2013
//Model:       SY_UNO

//These are all my LED bars on the display. I'm
//labeled them as they were named in the specifications
//sheet and assigned them there own output pin to the
//arduino board.

const int a = 1;
const int b = 2;
const int c = 3;
const int d = 4;
const int e = 5;
const int f = 6;
const int g = 7;
const int p = 8;

//I am telling arduino that all the pins a through g and p
// are output pins

void setup()
{
 pinMode(a, OUTPUT);
 pinMode(b, OUTPUT);
 pinMode(c, OUTPUT);
 pinMode(d, OUTPUT);
 pinMode(e, OUTPUT);
 pinMode(f, OUTPUT);
 pinMode(g, OUTPUT);
 pinMode(p, OUTPUT);  
}

//I am going to use the delay as my timer and tell arduino to
//turn on the related bars that are needed to display the correct
//number associated with 1 through 9.

void loop()
{
 //this is for the number 0
 digitalWrite(a, HIGH);
 digitalWrite(b, HIGH);
 digitalWrite(c, HIGH);
 digitalWrite(d, HIGH);
 digitalWrite(e, HIGH);
 digitalWrite(f, HIGH);
 digitalWrite(g, LOW);
 digitalWrite(p, HIGH);
 delay(1000);
 
//this is for the number 1
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(p, HIGH);
delay(1000);

//this is for the number 2
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
digitalWrite(e, HIGH);
digitalWrite(d, HIGH);
digitalWrite(p, HIGH);
delay(1000);

//this is for the number 3
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(p, HIGH);
delay(1000);

//this is for the number 4
digitalWrite(f, HIGH);
digitalWrite(b, HIGH);
digitalWrite(g, HIGH);
digitalWrite(c, HIGH);
digitalWrite(p, HIGH);
digitalWrite(a, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
delay(1000);

//this is for the number 5
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(p, HIGH);
delay(1000);

//this is for the number 6
digitalWrite(a, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(c, HIGH);
digitalWrite(e, HIGH);
digitalWrite(d, HIGH);
digitalWrite(p, HIGH);
digitalWrite(b, LOW);
delay(1000);

//this is for the number 7
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
digitalWrite(d, LOW);
digitalWrite(p, HIGH);
delay(1000);

//this is for the number 8
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(p, HIGH);
delay(1000);

//this is for the number 9
digitalWrite(a, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(p, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
delay(1000);
}

TAGS added by moderator - use the # sign to add them  next time

PaulS

That docx file was downloaded 0 times, and will remain that way, as far as I'm concerned. If you can't post your questions here, I can't go read them there.

CrossRoads

Your word docs have issues.
You appear to be attempting to multiplex the digits, that part is fine.
I don't see any current limit resistors, need at least per digit between the arduino cathode drive pins and each device.
You will drive 1 segment high, pull the cathode low, then  high.
Drive the next segment high, pull the cathode low, then high.
Repeat for the remaining 12 segments (or 14 if using the decimal point).
Leave each segment on for 2380microSeconds for aboout 30 Hz refresh rate.
(1/14/30Hz)
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

shanecy

I've made some corrections. Hopefully this helps.

CrossRoads

Quote
//I am going to use the delay as my timer and tell arduino to
//turn on the related bars that are needed to display the correct
//number associated with 1 through 9.

That's certainly 1 way to do it.
Another would be to define the digits to be on/off  for each character in an array,
have another array for the pins used, and loop thru both to multiplex the display.
delay( ) will introduce time drift into your results, a more precise way is to use the micros( ) feature, every pass thru loop see if it is time to update the display for the next segment - turn off the prior segment, turn on the next one.
Then your code can be doing other stuff as well while the time elapses, vs sitting dead in the delay period.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

BulletMagnet83

Your code's going to need some serious alteration, once you're able :) As it stands, what you're doing could easily be accomplished with a handful of logic ICs. You could throw together a counter-upper-thingy in an couple of hours with no need to write any code at all!


Go Up