7 segment basic

not really a question but found this. code and it works so well ! had to search. for. a long time.
this code. displays numbers on your 7 segment display
int anodeLeds = {4, 5, 6, 7, 8, 9, 10};
int cathodeDigits = {1, 11, 12, 13};
int displayBuf[2];

int i = 0, j = 0;
int startTime = 0;
int endTime;
int num_array[10][7] = {
{ 1, 1, 1, 1, 1, 1, 0 }, // 0
{ 0, 1, 1, 0, 0, 0, 0 }, // 1
{ 1, 1, 0, 1, 1, 0, 1 }, // 2
{ 1, 1, 1, 1, 0, 0, 1 }, // 3
{ 0, 1, 1, 0, 0, 1, 1 }, // 4
{ 1, 0, 1, 1, 0, 1, 1 }, // 5
{ 1, 0, 1, 1, 1, 1, 1 }, // 6
{ 1, 1, 1, 0, 0, 0, 0 }, // 7
{ 1, 1, 1, 1, 1, 1, 1 }, // 8
{ 1, 1, 1, 0, 0, 1, 1 }
}; // 9
void setup() {
// put your setup code here, to run once:
for (int i = 0; i < 7; i++)
{
pinMode(anodeLeds*, OUTPUT);*

• }*
• for (int i = 0; i < 4; i++)*
• {*
_ pinMode(cathodeDigits*, OUTPUT);_
_
}_
_
displayBuf[1] = 0; // initializes the display*_
* displayBuf[0] = 0;*
}
void loop() {
* // put your main code here, to run repeatedly:*
* refreshDisplay(displayBuf[1], displayBuf[0]);*
* // delay(1000);*
* endTime = millis(); // increments the counter approximately once a second*
* if ((endTime - startTime) >= 1000)*
* {*
* if (++i > 9)*
* {*
* i = 0;*
* if (++j > 9) j = 0;*
* }*
* displayBuf[0] = i; // send the updated count to the display buffer*
* displayBuf[1] = j;*
* startTime = endTime;*
* }*
}
void displayDigit(int digit)
{
* for (int i = 0; i < 7; i++)*
* {*
digitalWrite(anodeLeds, num_array[digit]);
* }*
}
void refreshDisplay(int digit1, int digit0)
{
* digitalWrite(cathodeDigits[0], HIGH); // displays digit 0 (least significant)*
* digitalWrite(cathodeDigits[1], LOW );*
* digitalWrite(cathodeDigits[2], HIGH );*
* digitalWrite(cathodeDigits[3], HIGH );*
* displayDigit(digit0);*
* delay(5);*
* digitalWrite(cathodeDigits[0], LOW); // then displays digit 1*
* digitalWrite(cathodeDigits[1], HIGH);*
* digitalWrite(cathodeDigits[2], HIGH );*
* digitalWrite(cathodeDigits[3], HIGH );*
* displayDigit(digit1);*
* delay(5);*
}

If it's not a question why did you post it (for the third time....)

You may like it (for some unfathomably esoteric reason), but it's horrendously inefficient.

An array of ints for the segments? And for boolean flags at that! 140 bytes for what could be stored in 10.

Also it's 1 second timing using millis() is borked. This...

``````startTime = endTime;
``````

Should be like this to avoid drift...

``````startTime += 1000;
``````

Edit: Oh, and as someone else pointed out on another thread use unsigned long for times if you want the maths to work correctly and not bomb after 32768 ms (≈ 32 seconds).

And you should learn to use tags. So many things wrong really!