Hi all -
Im making a scoreboard and have 2 - 2 digit LED Displays from sure. The code works great - up down for both and reset. the problem im having is the non lit segments flicker madly at all times. I know the displays are not the problem as they don't flicker on the demo driver board.
attached is the code - please advise?
I think its a brightness/DIMM pin issue - but beyond that im really lost
Im making a scoreboard and have 2 - 2 digit LED Displays from sure. The code works great - up down for both and reset. the problem im having is the non lit segments flicker madly at all times. I know the displays are not the problem as they don't flicker on the demo driver board.
attached is the code - please advise?
I think its a brightness/DIMM pin issue - but beyond that im really lost
Code:
//define clock and data pins
int clockPin = 12;
int dataPin = 11;
int VclockPin = 9;
int VdataPin = 8;
//copy and paste for every button
//Home Up
int upButtonPin = 4;
int lastUpButtonState = 0;
//Visitor Up
int VupButtonPin = 7;
int VlastUpButtonState = 0;
//Home Dn
int downButtonPin = 5;
int lastDownButtonState = 0;
//Visitor Dn
int VdownButtonPin = 3;
int VlastDownButtonState = 0;
//Reset
int resetButtonPin = 6;
int lastResetButtonState = 0;
//The number to be displayed on the home display
int displayedNumber = 0;
//The number to be displayed on the visitor display
int VdisplayedNumber = 0;
//the values that must be written out to the shift registers
byte seg_codes[] = { 0x7e, 0x30, 0x6d, 0x79, 0x33, 0x5b, 0x5f, 0x70, 0x7f, 0x7b };
//converts num to the proper 7 segment value and writes to the home display
void displayNum(int num)
{
int digit1 = seg_codes[num%10];
int digit10 = seg_codes[num/10];
shiftOut(dataPin, clockPin, LSBFIRST, digit1);
shiftOut(dataPin, clockPin, LSBFIRST, digit10);
}
//converts num to the proper 7 segment value and writes to the visitor display
void VdisplayNum(int Vnum)
{
int digit1 = seg_codes[Vnum%10];
int digit10 = seg_codes[Vnum/10];
shiftOut(VdataPin, VclockPin, LSBFIRST, digit1);
shiftOut(VdataPin, VclockPin, LSBFIRST, digit10);
}
void setup()
{
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(upButtonPin, INPUT);
pinMode(downButtonPin, INPUT);
pinMode(VclockPin, OUTPUT);
pinMode(VdataPin, OUTPUT);
pinMode(VupButtonPin, INPUT);
pinMode(VdownButtonPin, INPUT);
}
void loop()
{
//if Home up button pressed
int upButtonState = digitalRead(upButtonPin);
if(lastUpButtonState == 0 && upButtonState == 1)
{
if(displayedNumber < 99)
{
displayedNumber++;
}
else
{
displayedNumber = 0;
}
}
lastUpButtonState = upButtonState;
//if Visitor up button pressed
int VupButtonState = digitalRead(VupButtonPin);
if(VlastUpButtonState == 0 && VupButtonState == 1)
{
if(VdisplayedNumber < 99)
{
VdisplayedNumber++;
}
else
{
VdisplayedNumber = 0;
}
}
VlastUpButtonState = VupButtonState;
//if down button pressed
int downButtonState = digitalRead(downButtonPin);
if(lastDownButtonState == 0 && downButtonState == 1)
{
if(displayedNumber > 0)
{
displayedNumber--;
}
else
{
displayedNumber = 99;
}
}
lastDownButtonState = downButtonState;
//if down button pressed
int VdownButtonState = digitalRead(VdownButtonPin);
if(VlastDownButtonState == 0 && VdownButtonState == 1)
{
if(VdisplayedNumber > 0)
{
VdisplayedNumber--;
}
else
{
VdisplayedNumber = 99;
}
}
VlastDownButtonState = VdownButtonState;
//if reset button pressed
int resetButtonState = digitalRead(resetButtonPin);
if(lastResetButtonState == 0 && resetButtonState == 1)
{
displayedNumber = 0;
VdisplayedNumber = 0;
}
lastResetButtonState = resetButtonState;
displayNum(displayedNumber);
VdisplayNum(VdisplayedNumber);
delay(150);
}