Hello,
I am attempting to make a 6 digit 7-segment counter using an Arduino micro and 3 double common anode 7-Segment displays.
I can't seem to get the timing correct when updating the display.
The display will correctly display the initial state of the counter array, counter[6] = {0, 0, 0, 0, 0, 0} but if I increment counter by 1.
the display glitches.
I am directly driving the displays from the arduino.
Here is the code I am using.
byte anodePins[] = {A0,A1,2,3,4,5};
int segmentPins[] = {6,7,8,9,10,11,12,13};
int digits[10][8] = {
{6,7,8,9,12,13,13,13},
{6,7,6,7,6,7,6,7},
{6,8,9,10,11,12,12,12},
{6,7,9,10,11,12,12,12},
{6,7,10,11,13,13,13,13},
{7,9,10,11,12,13,13,13},
{7,8,9,10,11,12,13,13},
{6,7,6,7,6,7,6,12},
{6,7,8,9,10,11,12,13},
{6,7,7,9,10,11,12,13}
};
int counter[6] = {0,0,0,0,0,0};
void setup()
{
int a, s;
for(a = 0; a < 6; a++)
{
pinMode(anodePins[a], OUTPUT);
anodesOff();
}
for(s = 0; s < 8; s++)
{
pinMode(segmentPins[s], OUTPUT);
segmentsOff();
}
}
void loop()
{
updateLeds();
incCount();
}
void anodesOff()
{
for(int a = 0; a < 6; a++)
{
digitalWrite(anodePins[a], LOW);
}
}
void segmentsOff()
{
for(int s = 0; s < 8; s++)
{
digitalWrite(segmentPins[s], LOW);
}
}
void updateLeds()
{
int p, s, q, z;
anodesOff();
segmentsOff();
digitalWrite(anodePins[0], HIGH);
for(p = 0; p < 8; p++)
{
digitalWrite(digits[counter[5]][p], HIGH);
}
anodesOff();
segmentsOff();
digitalWrite(anodePins[1], HIGH);
for(p = 0; p < 8; p++)
{
digitalWrite(digits[counter[4]][p], HIGH);
}
anodesOff();
segmentsOff();
digitalWrite(anodePins[2], HIGH);
for(p = 0; p < 8; p++)
{
digitalWrite(digits[counter[3]][p], HIGH);
}
anodesOff();
segmentsOff();
digitalWrite(anodePins[3], HIGH);
for(p = 0; p < 8; p++)
{
digitalWrite(digits[counter[2]][p], HIGH);
}
anodesOff();
segmentsOff();
digitalWrite(anodePins[4], HIGH);
for(p = 0; p < 8; p++)
{
digitalWrite(digits[counter[1]][p], HIGH);
}
anodesOff();
segmentsOff();
digitalWrite(anodePins[5], HIGH);
for(p = 0; p < 8; p++)
{
digitalWrite(digits[counter[0]][p], HIGH);
}
}
void incCount()
{
counter[5] = counter[5] + 1;
}
Any help will be greatly appreciated.