Pages: [1]   Go Down
Author Topic: four digit 7-segment display  (Read 1084 times)
0 Members and 1 Guest are viewing this topic.
Casorezzo, Milan, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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 digit
else {

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);
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 33
Posts: 1228
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think the last few lines are missing
Code:
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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27425
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You have the correct display type, common anode vs common cathode?
From the font, looks like common cathode is needed.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Casorezzo, Milan, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27425
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"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:
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);
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: