I’m running 150 WS2812b’s with an ATX/PC power supply. I’m attempting to add a block of code that will enumerate values from my arrSerialValues[] array, average them and write them out to the analog pins on my Arduino Uno.
Everything works great within my sketch until I add in the averaging code. Once I do that, all of my WS2812b leds blink red/blue continuously. I don’t believe that it’s power related, they appear to be functioning at full brightness. It seems more like memory, data corruption or a clock issue perhaps? I’ve tested the code with a simulator and the values are all valid. It’s just that the addition of the code causes loss of control to the digital WS2812b side.
I’ve tried several different ways of doing the averaging, each way ends with the same red/blue blinking.
I can’t get to pastebin from here right now, but I can post the entire sketch later if needed.
void loop() {
word tmpR = 0; word tmpG = 0; word tmpB = 0;
int low = 0; int high = 0;
word arraysize = 5;
for (byte i = 0; i < sizeof(arrPrefix); ++i) {
waitLoop: while (!Serial.available()) ;;
if (arrPrefix[i] == Serial.read()) { continue; }
i = 0;
goto waitLoop;
}
for (byte i = 0; i < NUMLEDS; i++) { // read the transmitted data
for (byte j = 0; j < 3; j++) {
while(!Serial.available());
arrSerialValues[i][j] = Serial.read();
}
leds[i] = CRGB(arrSerialValues[i][0], arrSerialValues[i][1], arrSerialValues[i][2]);
}
// from here*
for (int i = 0; i < 2; i++) {
tmpR = 0; tmpG = 0; tmpB = 0;
switch (i) {
case 0:
low = 5; high = low + ((arraysize * 2) + 1);
break;
case 1:
low = 91; high = low + ((arraysize * 2) + 1);
break;
}
for(int k = low; k < high; k = k+2){
tmpR += arrSerialValues[k][0];
tmpG += arrSerialValues[k][1];
tmpB += arrSerialValues[k][2];
}
tmpR /= (high - low) / 2;
tmpG /= (high - low) / 2;
tmpB /= (high - low) / 2;
tmpR += (tmpR * ANALOGSCALE) / 100; if (tmpR > 255) { tmpR = 255; }
tmpG += (tmpG * ANALOGSCALE) / 100; if (tmpG > 255) { tmpG = 255; }
tmpB += (tmpB * ANALOGSCALE) / 100; if (tmpB > 255) { tmpB = 255; }
switch (i) {
case 0:
writeRightSide(tmpR, tmpG, tmpB);
break;
case 1:
writeLeftSide(tmpR, tmpG, tmpB);
break;
}
}
// to here*
FastLED.setBrightness(BRIGHTNESS);
FastLED.show();
delayMicroseconds(SHOWDELAY);
}