Go Down

### Topic: four digit 7-segment display (Read 1 time)previous topic - next topic

#### gianlucalongoni

##### Jan 18, 2013, 05:18 pm
Hi everybody!
i found this recipe on the arduino cookbook. It pretend to drive a four digit 7-segment display, but i'm not shure about that, not at all...i mean, i built the circuit...but as i attempt to represent on the display a more-than-one-digit number...it stops working, and all segments of the digit i need are lit. I think that the point is that through the digit pins, i enable all the segments of a digit to be illuminated, but the bitmap i can send to the digits is the same for all of them...!isn't it?
Here's the sketch:
Code: [Select]
`const int numeral[10] = {//ABCDEFG /dp B11111100, // 0 B01100000, // 1 B11011010, // 2 B11110010, // 3 B01100110, // 4 B10110110, // 5 B00111110, // 6 B11100000, // 7 B11111110, // 8 B11100110, // 9};// pins for decimal point and each segment const int segmentPins[] = { 4,7,8,6,5,3,2,9}; const int nbrDigits= 4; const int digitPins[nbrDigits] = { 10,11,12,13};void setup() {for(int i=0; i < 8; i++) pinMode(segmentPins[i], OUTPUT); for(int i=0; i < nbrDigits; i++) pinMode(digitPins[i], OUTPUT);}void loop() {int value = analogRead(0); showNumber(value);}void showNumber( int number) {if(number == 0) showDigit( 0, nbrDigits-1) ; // display 0 in the rightmost digitelse {for( int digit = nbrDigits-1; digit >= 0; digit--) {if(number > 0) {showDigit( number % 10, digit) ; number = number / 10;}}}} void showDigit( int number, int digit) {digitalWrite( digitPins[digit], HIGH ); for(int segment = 1; segment < 8; segment++) {boolean isBitSet = bitRead(numeral[number], segment); isBitSet = ! isBitSet; digitalWrite( segmentPins[segment], isBitSet);} delay(5);`

#### Msquare

#1
##### Jan 18, 2013, 06:00 pm
I think the last few lines are missing
Code: [Select]
`digitalWrite( digitPins[digit], LOW ); }`

Otherwise there are two possible failure causes - you circuit is wrong, or you made a simple keyin error in the program (isn't there a downlaodbale version - the formatting is to bad to be from a book)

To verify the circuit, do a simple program that only turn HIGH two pins - one from the digit select and one from the segement. If only one segment lights up, good, try the other combinations.  You should be able to write a program that goes through all 4*7 combinations with a short delay on each - a sort of running light.

#2
##### Jan 18, 2013, 06:50 pm
You have the correct display type, common anode vs common cathode?
From the font, looks like common cathode is needed.
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.

#### gianlucalongoni

#3
##### Jan 18, 2013, 09:24 pm
Quote
I think the last few lines are missing

guess what!
those lines were on the next page...!...
I'm sorry for my carelessness...!
Anyway i found a bug, however...defining the showDigit function, in the For loop, the counter must start from zero, isn't it?...
i have a four digit 7-segment common anode display. The rightmost bit in each element of the bitmap array coincides with the DP led in the display, that has to be always off (i don't have to represent decimal values), and if i put "int segment=1" in the for loop conditions, that led is always lit.

thank you so much for the help!

#4
##### Jan 18, 2013, 10:13 pm
"i have a four digit 7-segment common anode display"

So in here, where you changed from 0 to <8 if I understand correctly,
if a  bit in numeral[ x ] is 1, you write a Low out:

Code: [Select]
` void showDigit( int number, int digit) {digitalWrite( digitPins[digit], HIGH ); for(int segment = 1; segment < 8; segment++) {boolean isBitSet = bitRead(numeral[number], segment); isBitSet = ! isBitSet; digitalWrite( segmentPins[segment], isBitSet);} delay(5);`
You could make the overall program more responsive by checking if >=5mS had elapsed every pass thru void loop, and changing the segment turned on that time. The rest of the 5mS be doing other stuff instead of just sitting in delay(5);
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.

Go Up

Please enter a valid email to subscribe