Electronics > Beginners
7 segment 4 digit
maze49:
Hi,
I introduce myself, begginer in electronic and coding. I got Arduino starter set and I really enjoy it.
My question is about the 7 segment 4 digit.
I display the same number on 4 digit OK
I display 1 2 3 4 with delay OK
I display 1234 with multiplexing OK
I display 0-9999 with push button OK
But, is it possible to control each digit individualy?
For example, Digit1 = 0-9 when Digit1 is 9 Digit2 = 1-5 when Digit2 is 5 Digit3 = 1-9 when Digit3 = 9 Digit4 = 1-9
hope to be clear :/
Thanks for your knowledge!
admiralk:
I am not familiar with 4 digit displays, but I would start by trying to control just a single digit. In other words, try just displaying 0-9 on the first digit while leaving the rest blank. Then do the same with the second digit, and so forth.
mariush:
The answer is it really depends on how your actual seven segment display is built.
The display may have a tiny controller chip between your arduino and the actual digits, in order to simplify the interaction with the digits. If this is the case, you're using SPI or I2C to "talk" to that chip sending it commands, and the controller chip does the harder work for you turning individual segments in all those digits.
If the seven segment digits have no in-between chip (this is most likely what you have) then there's two main kinds of such displays:
1. Common anode digits - these are digits that have one pin to give voltage to all segments and when you connect any other pin to ground (sink) that individual segment light up because electricity flows from the common anode pin to that other pin, through the led.
2. Common cathode digits - these have one pin for each segment through which you give voltage and all the cathodes of the leds inside the digit are connected to a single pin, which you usually connect to ground. You turn on individual segments by sending voltage through one of those pin (usually 8 of them, the seven segments of the digit plus the dot)
When there's multiple digits, there's usually one common anode or one common cathode for each digit, and the 8 segments of all digits are connected together.
For example, if you have a common anode display and you send power to all 4 common anodes, then when you connect one of the 8 other pins to ground, that segment of each digit will light up, because all four anodes receive voltage.
If you want to display numbers like 1234, you can't send voltage to all 4 anodes all the time, because the top right segment of "1" will also show up on 2, which you don't want.
So, you turn only one digit at a time: prepare the 8 segment pins for digit 1, turn on digit 1, wait a few ms, turn off digit, set the 8 segments for digit 2, turn on power to digit 2, wait a few ms ... repeat, and loop back to digit 1 for ever.
If you're asking how to display a number like "15" on a 4 digit display , how to extract the number 1 and the number 5, you have mathematical functions that give you the remainder of a division ... so you can say something like
digit[3] = remainder of value divided by 10
value = value / 10
digit[2] = remainder of new value divided by 10
value = value / 10
...
digit[0] = remainder of value divided by 10
now you may have digit[0]=0 , digit[1]=0, digit[2]=1 , digit[3] = 5
If you don't want to display 0015 then you can simply do something like
start_from=0;
while (digit[start_from]==0 && start_from<3) start_from=start_from+1;
and now start_from will be the first digit that has non zero value, or the 4th digit.
digit
maze49:
Hi,
Thanks admiralk,
Yes I do.
You are right, it is the best way to understand how 7 segment works.
mariush
Thanks for your explanations. I understand your code example and it looks like what I did.
Actually it works like this:
Digit1 and Digit2 count until 99 then restart to 0
When Digit1 and Digit2 write 99, Digit3 add 1 ect...
Now, I wanted to add "delay()"when it is 50 but my code doesn't like at all and I think to know why.
Because to display all my digit together I use "delayMicroseconds" for multiplexing.
What do you think about?
mariush:
Well, that's fairly simple.
Instead of one variable holding the number, have two variables each holding what's displayed on 2 digits.
Do the stuff I wrote for each variable, to get digit 0 + digit1 and for the second number digit 2 + digit 3
add a third variable, let's say counter.
This is the amount of time you want to spend displaying the numbers on the display before you update the two numbers (by reading them from pins or whatever)
For example, if you spend 1ms on each digit, you're gonna have ~4ms spend displaying the 4 digits, so you want to loop 50 ms / 4ms = 12.5 times ... let's say 12
So you set the counter to 12
if counter variable is 0 then
read number1
read number2
calculate digits
if (value is 50) set counter variable to number of loops for 50 ms
if (value is not 50) set counter variable to minimum amount of loops, let's say for 10 ms
end if
while counter > 0
display first digit , wait time
display second digit, wait time
display third digit, wait time
display fourth digit, wait time
counter = counter - 1
end while
repeat everything.
This method would work, but for that period of time where you loop through digits, you're not accepting any inputs.
A better method would be to learn to use interrupts, and set an interrupt on change.
When something changes on your input pins that are configured by you, your code is 'paused' and the arduino goes inside the function which does something, and when you exit out of that function, your loop resumes from where it left off .
So, your interrupt function can read the value on the pins every time the data on pins changes and update the two values and this way your values are always correct.
However, you can use two separate variables to keep what's shown on the digits, and only update these two variables when the counter variable goes down to 0.
Navigation
[0] Message Index
[#] Next page
Go to full version