If statement with array doesn't work(Im new)

In setup: I turn 40 into binary.

In Loop I want to blink led but led doesn't blink.

int arr[20];
int dec = 40;

    
void setup() {
Serial.begin(115200);
int i = 0, ArrLen;
    if(dec > 0)
    {
        while(dec > 0)
        {
            arr[i] = dec % 2;
            i++;
            dec = dec / 2;
        }
    }
}

void loop() {
for(byte i = 0; i < 7; i++){
  if(arr[i]>0){digitalWrite(D0,HIGH);}
  else {digitalWrite(D0,LOW);}

Serial.print(arr[i]);
delay(50);

}
Serial.println("");
delay(5000);

}

Did you forget to do something to D0 in setup?

(NB: this is NOT an installation issue)

1 Like

omg you are my hero <3

@safa1

Your post was MOVED to its current location 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.

That if statement is not necessary. You will get the same result with or without it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.