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