ok guys, i managed to fix my problems with the register, and im slowly building a driving function...but with all the delays when switching voltages...the display is not super bright and now noticeably flickery...im using delay(5) in between voltage changes and display clears. Longer delay causes flickeryness, shorter causes dimness...
here is my code...any solutions? so closeeeeee!!
//shows the 4 digits on screen
void show_num(int a,int b,int c,int d){
//turn on dots
clearSegments();
swapGround(ground1);
digitalWrite(dotsPin, HIGH);
delay(5);
switch (a){
case 1:
clearSegments();
swapGround(ground2);
setRegisterPin(5, HIGH); //with g2,
setRegisterPin(6, HIGH);
writeRegisters();
delay(5);
break;
}
switch (b){
case 1:
clearSegments();
swapGround(ground2);
setRegisterPin(3, HIGH); //with g2,
setRegisterPin(4, HIGH);
writeRegisters();
delay(5);
break;
case 2:
clearSegments();
swapGround(ground1);
//bottom right
setRegisterPin(3, HIGH); //with g2
setRegisterPin(4, HIGH); //with g2
setRegisterPin(5, HIGH);
writeRegisters();
delay(5);
clearSegments();
swapGround(ground2);
//bottom right
setRegisterPin(2, HIGH); //with g2
setRegisterPin(4, HIGH); //with g2
writeRegisters();
delay(5);
break;
}
switch (c){
case 1:
clearSegments();
swapGround(ground2);
digitalWrite(ledPins[2], HIGH);
setRegisterPin(0, HIGH);
writeRegisters();
delay(5);
break;
}
switch (d){
case 1:
clearSegments();
swapGround(ground1);
digitalWrite(ledPins[5], HIGH);
digitalWrite(ledPins[2], HIGH);
delay(5);
break;
}
}
void loop(){
show_num(1,2,1,1);
}
Function descriptions:
clearSegments() - resets all pins to low
swapGround() - switches the voltages
clearRegisters() - resets registered pins to low
setRegisterPin() - set a register pin to high or low
writeRegisters() - update display with updated register
void clearSegments(){
//turn off normal pin leds
for (int x=0; x<ledLength; x++){
digitalWrite(ledPins[x], LOW);
}
digitalWrite(dotsPin, LOW);
clearRegisters();
writeRegisters();
}
void swapGround(int gr){
if (gr==ground1){
// Serial.println("switched to ground 1");
digitalWrite(ground1, LOW);
digitalWrite(ground2, HIGH);
}
else if (gr==ground2){
//Serial.println("switched to ground 2");
digitalWrite(ground2, LOW);
digitalWrite(ground1, HIGH);
}
}