I'm trying to program an LED run where, starting with LED 1 and ending with LED 50 they light up in sequence and stay on. For some reason, after the run completes the first time, the lights turn off and the run repeats. Then everything stays lit. I cannot for the life of me figure out why.
I'm using an Uno R3 board and a WS2812B string of 150 LEDs.
Small update: It's only the first time after I send the code to the board that it throws an error. Hitting reset on the board doesn't have this problem.
I have tried a for loop and got the same result. The LEDs are being powered by a 5V, 15A power brick. I have a string of 150 LEDs, I've declared through 51 in the code and only make use of 0-49.
There seems to be an error that happens when the code is run for the first time after compiling. When I press the reset button on the board the code runs as intended.
This gives me the same error after compiling. I'm guessing its something to do with the data transfer rather than the code itself, since it only happens the first time after compiling.
Based on your description, the code works just fine when you press the reset?
But it runs again when you compile and upload?
Most likely, that is just an artifact of the uploading process. When you upload code, your PC resets the board so the bootloader on the board has a chance to "see" if the PC is attempting to upload code. If yes, it accepts the new code. If not, it times out and then executes the code already on the board.
After the upload is complete, the board is reset again to begin execution of the new code. Depending on the timing of everything, your board is probably starting to run the existing code and then gets reset to upload the new code and then runs that so you are seeing the old code start and the new code run.
You can test this out by changing the color of the LEDs to something besides 255,255,255. Maybe red (255,0,0).
Make the change and upload the new code and see what you get - white LEDs the first time followed by red LEDs the second time?