Hi
I am making a standalone countdown timer using an Atmega328p and a ds1307 and 2 7segment LEDs
I want to include a calculation that uses if statements based on the information extracted from the ds1307.
I have 2 queries.
Firstly, I want to take extract the current year ad month from the current time as returned by the ds1307 and use them in a calculation.
For example if year = 2011 and month = November then do calculation based on result.
I have not got the calculation in front of me but next post I will supply it.
Secondly I am not seeing how to pass the information in decimal form on to the 7 segment LEDs.
I have read several tutorials on making clocks etc from the ds1307 and using 7 segment displays to display the time but how to pass on the data eludes me. I don't think I need to use shift registers to pass the information on to my 2 led display characters as think I will have plenty of outputs from the atmega328p.
If anyone is willing to help steer me in the right direction I will post some more exact details of what I want to do when I am in front of my computer.
I have also successfully coded it to adjust for daylight savings here in NewZealand so I hope I can get to grips with the code.
Giving you some food for thought for your display:
If your 7seg displays are just that (no controller or anything) then you do not pass "decimal" to them, you decide which of the 7 segment to light up or not. With a bit of luck the pattern you create is a recognizable number. Something along the lines of
byte seven[7][10] = {
HIGH, HIGH, HIGH, HIGH, HIGH, LOW, // which segments make the shape "0"
LOW, HIGH, HIGH, LOW; LOW, LOW, // which segments make the shape "1"
: }
You then do a digitalWrite on the right pin the content of seven[digitvalue][segment]
Your 7 seg displays will need 2x7=14 digital outputs. By using some of the analog inputs as digitals outputs you have enough pins for that and the DS1307, but not a lot else. Remember to put a 330 Ohm resistor between each output and the 7 seg display pin. You need to limit the current for the worstcase "88" display so the total mA is (well) below 200mA.
To be more precise what I am doing is finding the number of days between dates by using the following calulation.
If month is 1 or 2 add 12 to the month and subtract 1 from the year then apply thew following
365year + year/4 - year/100 + year/400 + date + (153month+8)/5 all ints rounded down
Do this for the current date and the future date I want the event counter to be for and subtract one from the other then display the days remaining on the 7 segment display.
For instance 5 March 2011 to 15 March 2011 would be
3652011+2011/4-2011/100+year/400+5+(153month+8)/5
or
734015+502=734067-20+5+5=734057+93=734150
734015+502=734067-20+5+15=734067+93=734160
Subtract 1 from the other and it returns 10
So thats the math done
I have been doing some further reading and it looks like the easiest way might be to use a bcd to 7 segment ic I suppose I could use one as they are cheap and cheerful and would probably save me a bit of code if that was the easiest way to do it.
Shift registers are only really required if the display is constantly counting down a digit aren't they? to cascade bytes through quickly.
Msquare
I was planning on multiplexing the 2 digits and using pov to display the characters as I thought that was easier to do and only required 2 330 ohm resistors on the grounds. (I have common anode digits currently for testing purposes)
So if I was using assembly I would guess I needed to make a look up table and then the result of my equation would select the 'digit' to display from the table.
What is the easiest way to do this using c in an arduino sketch?
So the psuedo code would be
get date from ds1307
apply calculation to year and month at midnight
display result on 7 segment display
It will be designed to be left powered on for the duration so if it applies the calculation only at midnight then it will appear to countdown 1 per day until the event is reached and then I can flash "00" perhaps on the display after that.
Paul
Hopefully that answers what I was so vague about before?
The calculation is sort of irrelvant - you simply write it as you explained it. Use long instead of int as you have largish numbers.
You have some "interesting" ideas about the 7seg displays. There is no magic about them. They are just 14 LEDs. It does not matter to the LEDs or the Arduino if they change once a day or a thousand times a second. The circuit and code would be the same.
The choice between 14 digital outputs, shift registers (3 outputs) or BDC chips (8 outputs), static or POV (almost halving number of outputs), depends on your time and money going into software or electronics and if you do have enough ports. If you do not like writing the array lookup, then use a BCD chip (some chips may include the currentlimit circuitry). Me, I would prefer a software solution, and keeping the electronics count to as low as possible.
You can NOT just put a resistor on the common line (irrespectve if it is common anode or cathode). If you do that then the "1" will shine bright and the "8" will be rather dim. The resistor limits the current, and the LEDs are wired in parallel so thet when 4 LEDs are lit they get 1/4 of the current each. As current=brightness... It is a beginners mistake (I made it myself) to think that you can "factor" common components like that.
Okay. None of that was helpful really thanks.
I am after practicality, and that whole post didn't really help me go forward in the slightest sorry.
I do not think there is any magic in 7 segment leds, I just am not sure functionally of the easiest way to write the software to interface with them.
I have also completed a tutorial to multiplex the leds and countdown to 0 from 20 and noticed absolutely no difference in brightness so I will reserve judgement on that one for now also.
They seemed to all be one brightness but it could be just my perception.
I suppose some of my confusion is coming from the fact that I am so used to assembly, not c or c++
So it seemes to me in the tutorials I am reading that people are setting up the characters as it specifying what leds to light up for each charater and then they are only using the serial.Print command to "send the DS1307 output to the leds"
It looks like a step is missing to my mind, but it is probably just my lack of knowledge regarding c programming.
For instance in the following code accessed by clicking the led.txt part way down
I cannot understand how the data is passed to the led display. (perhaps if the code was 15 pages long like in assembly I would get to grips with it easier :D)
I think what I am looking at is he has created a variable called dummy and then reads the data from the rtc into it and then it outputs it to the leds by the series of "if dummy=()" statements below, would that be correct?
I don't mean to be unappreciative of your help because I am not. Perhaps there are some more tutorials out there that I need to read before tackling the coding part.
The Digital Clock from the instructable is using a 4017 IC to decode the output. So the arduino code is an input for the 4017, not directly for the display.
It uses just one line to turn the leds in a segment on:
PORTD = num_array[display_time[y]];
This is the equivalent of multiple digitalWrites. The variable has a value that, when expressed in binary, shows you the led that will be on (1) or off (0) . It is accessing the pins directly from an array.
If the displays are multiplexed, you just need to display one digit at a time and then alternate between digits. If you manage to do that quick enough, the human eye will not notice that. This code is using the 4017 for that purpose. But if you have enough pins free, you can skip it.
If you wan an easier code and use less pins, just grab some shiftOut chips.
I see
So thats an example of sending the bcd straight to the display. I will look out for a similar tutorial just using the output pins.
As this will be standalone I have no reason to need to use less pins so I will see what I can find.
Thank you.