I'm slightly modifying a script I found on the web regarding running a 7 segment display. The original script was set to run on pins 0-6 but I need to retain serial comms for my project.
I've stepped through the script in my head and on paper a few times and can't figure out why I'm having this issue.
Any number below 4 is displaying completely wrong. I've double checked that the bytes are set up correctly for my CA display. I'm at a loss.
Here's the code. Any comments, quips, or suggestions are greatly appreciated. I'm trying to learn to be concise and practical with my coding.
// 0 1 2 3 4 5 6 7 8 9
byte numDef[10] = {64, 121, 36, 48, 25, 18, 2, 120, 0, 24};
void setup()
{
for (int i = 2; i < 9; i++)
{
pinMode(i, OUTPUT);
}
clearDisplay();
}
void loop()
{
for (int i = 0; i < 10; i++)
{
writeDisplay(i);
delay(500);
clearDisplay();
}
}
void writeDisplay(int num)
{
byte segments = numDef[num];
for (int i = 2; i < 9; i++)
{
int b = i - 2;
int bitVal = bitRead(segments, b);
digitalWrite(i, bitVal);
}
}
void clearDisplay()
{
for (int i = 2; i < 9; i++)
{
digitalWrite(i, HIGH);
}
}