Help with arduino code

I’m quite new to arduino.
Basically I want my 8-bit LED sequence to go left to right and display two digits of a time, I tried to work it out but I just can’t. I’d love some help, thanks in advance.

Here’s the code:
int ledPin = {12,11,10,9,8,7,6,5};
unsigned long maxCount = 1824506 ;
int delayInterval = 1000;

void setup() {
// put your setup code here, to run once:
delay(5000);
for (int i = 0; i < 13; i++)
{
pinMode(ledPin*, OUTPUT);*

  • }*

}
void loop() {

  • // put your main code here, to run repeatedly:*

  • delay(5000);*
    for (int counter = 0; counter < maxCount ; counter++)
    {displayBinary(counter);
    delay(delayInterval);
    }
    }
    void displayBinary(byte numToShow)
    {

  • for(int i=0; i < 8;i++)*

  • {*

  • if(bitRead(numToShow, i)==1)*

  • {*

_ digitalWrite(ledPin*, HIGH);_
_
//delay(1000);_
_
}_
_
else*_
* {*
_ digitalWrite(ledPin*, LOW);
//delay(100);
}
}
}*_

Please remember to use code tags when posting code

@melodoro99

Your topic was Moved to it's current location / section as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Post your code in code tags so that the ledPin array indexes do not get eaten by the forum software.

I tried to work it out but I just can't.

It would help if you describe the problem. i would try to compile your code, but the forum software messes it up without code tags so cannot compile it.

If you have 8 leds, you can not display “2 digits” since 8 bits == 1 byte == 0…255.

Your counter variables is of type long which uses 4 bytes but your function displayBinary() takes a byte variable as a parameter. As a result, counter gets truncated to the lower 8 bits every time that function is called.

This will sequence through all 256 values

const int ledPin[] = {12, 11, 10, 9, 8, 7, 6, 5};
const int ledCount = sizeof(ledPin) / sizeof(ledPin[0]);
const int delayInterval = 1000;

void setup() {
  // put your setup code here, to run once:
  delay(5000);
  for (int i = 0; i < ledCount; i++)
  {
    pinMode(ledPin[i], OUTPUT);
  }
}


byte counter = 0;

void loop() {
  // put your main code here, to run repeatedly:
    displayBinary(counter);
    delay(delayInterval);
    counter++;
}

void displayBinary(byte numToShow)
{
  for (int i = 0; i < 8; i++)
  {
    if (bitRead(numToShow, i) == 1)
    {
      digitalWrite(ledPin[i], HIGH);
    }
    else
    {
      digitalWrite(ledPin[i], LOW);
    }
  }
}