7 segment 4 digit - Page 1
Forum section: electronics / beginners

author: maze49
author_rank: Newbie
timestamp: December 23, 2019, 12:37:33 pm
content: 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 OKI display 1 2 3 4 with delay OKI display 1234 with multiplexing OKI display 0-9999 with push button OKBut, 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-9hope to be clear :/Thanks for your knowledge!

author: admiralk
author_rank: Regular Contributor
timestamp: December 23, 2019, 02:52:04 pm
content: 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.

author: mariush
author_rank: Super Contributor
timestamp: December 23, 2019, 03:17:48 pm
content: 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 likedigit = remainder of value divided by 10value = value / 10digit = remainder of new value divided by 10value = value / 10...digit = remainder of value divided by 10now you may have digit=0 , digit=0, digit=1 , digit = 5If you don't want to display 0015 then you can simply do something likestart_from=0;while (digit==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

author: maze49
author_rank: Newbie
timestamp: December 23, 2019, 07:18:30 pm
content: Hi,Thanks admiralk,Yes I do.You are right, it is the best way to understand how 7 segment works.mariushThanks 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 0When 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?

author: mariush
author_rank: Super Contributor
timestamp: December 23, 2019, 08:18:11 pm
content: 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 3add 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 12So you set the counter to 12if counter variable is 0 thenread number1read number2calculate digitsif (value is 50) set counter variable to number of loops for 50 msif (value is not 50) set counter variable to minimum amount of loops, let's say for 10 msend ifwhile counter > 0display first digit , wait timedisplay second digit, wait timedisplay third digit, wait timedisplay fourth digit, wait timecounter = counter - 1end whilerepeat 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.

author: maze49
author_rank: Newbie
timestamp: December 23, 2019, 09:40:23 pm
content: "Well, that's fairly simple"Not totally for meI think to understand what you explain me. I must split each time the 4 digit are displaying in the loop like this I can increments a pause in the code without loosing the values.So I tried but I do wrong because the problem is still here.void loop(){number++;pickDigit(2);pickNumber(number/1000%10);delayMicroseconds(100);pickDigit(1);pickNumber(number/100)%10);delayMicroseconds(100);pickDigit(4);dispDec(3);pickNumber(number/10)%10);delayMicroseconds(100);pickDigit(3);pickNumber(number%10);delayMicroseconds(100);if (number > 50){number=0;delay(500);}So, when digit write 50 it go to 0 but the delay broke the code.

author: admiralk
author_rank: Regular Contributor
timestamp: December 24, 2019, 01:27:10 am
content: If you are going to show code, you should copy and paste what you are using instead of typing it out. Code tags (the # button) help also.Anyway, I have no idea what those functions do, but I would guess thatCode:pickDigit()selects which digit you want to light. If that is the case and you are only using the first two, do not even bother to call the other two. But then again, you callCode:dispDec()only on one of the digits so if that is the digit you are trying to display, you cannot get to 50 since it is more than one digit.Without knowing what the functions do (I do not know Arduino, if they are part of that) there is not much else I can say since I am completely confused right now.

author: Raj
author_rank: Frequent Contributor
timestamp: January 04, 2020, 03:38:37 pm
content: Master the use of % symbol and & symbol.Even a kid knows +,-, /,* symbolYour answer lies in codeLike you read 12 from first sensor, and 25 from secondYou have display that can show 4 digit number but you can physically separate them to make it into a 2, 2 digit displayNow all you need to do is mathsEg((12*100)%100)+(25)Aka ((num1*10)%100)+num2