kitesurfer1404 / WS2812FX

WS2812 FX Library for Arduino and ESP8266
MIT License
1.6k stars 347 forks source link

Wrong color on serial control #11

Closed silenoth closed 7 years ago

silenoth commented 7 years ago

Hi first thanks for this library was just what I was looking for but I have a problem with the hexadecimal colors, when requesting the color 0xFF0000 (red color) in the led strip this throws the color 0x00FF00 (green color), for example:

When I request 0xFF0000 -> serial print line: FF0000 When I request 0x00FF00 -> serial print line: FF00

Why is this? Why are the first two zeros removed?

thank you very much

there is an example red green

kitesurfer1404 commented 7 years ago

It's in line 102 of serial_control.ino: Serial.println(ws2812fx.getColor(), HEX); It's kind of an issue with Serial.println printing hex-values. Leading zeros are dropped.

If you need leading zeros, you might want to add this right before that line:

if(ws2812fx.getColor() < 0x100000) { Serial.print(F("0")); } if(ws2812fx.getColor() < 0x010000) { Serial.print(F("0")); } if(ws2812fx.getColor() < 0x001000) { Serial.print(F("0")); } if(ws2812fx.getColor() < 0x000100) { Serial.print(F("0")); } if(ws2812fx.getColor() < 0x000010) { Serial.print(F("0")); }

That's a quick and very dirty way, I admit. You might want to take a look at sprintf, but using sprintf added more than 2kb of code to my compiled sketch.

Let me know if that helps. I think, I'll add this to the sketch as well. Maybe an additional 0x on the output.

EDIT: added code to the development branch