The behaviour of your program is undefined because you're reading past the end of your array.
In C/C++, the sizeof
operator always gives you the size of something in bytes. It doesn't directly tell you the number of items in an array. Since int
is usually 2 bytes for Arduino programming, the pinCount
variable is actually being initialised to 10 (5 items x 2 bytes each).
The result is that each for
loop is actually doing 10 iterations. The first 5 iterations are OK, reading correctly from the ledPins
array. However, the rest of the iterations are reading whatever data happens to be in memory after that. This means it could be trying to initialise and switch on any pin, potentially including 0 and 1.
I can't guarantee that this is the source of the problem, but it's certainly very important to fix.
The solution is quite easy though. Divide the total size of the array by the size of a single element:
int pinCount = sizeof(ledPins) / sizeof(int);