I've been doing a fade function for the NeoPixels. However, the moment I have maximum brightness for the pixels, I noticed there 2 colours even though in my function I have only specified one colour.
Some strips are one colour and the others are another colour. I specified the colour to be blue for the strips however many strips are blue and the strips nearer the end are green (but closer to a blue-green colour).
Is there any way to keep the colour even when the brightness changes? I've read somewhere online a different colour is seen with different brightness levels i.e. setPixelColor(brightness, r,g,b)
.
I've also tried FastLED library and followed documentation. However, the lights are not doing what it has said in the codes, I've tried leds[i].fadeLightBy(200)
and it has given me no result.
My code for the fade function (edited from http://moving-rainbow.readthedocs.io/en/latest/guide/fade-in-and-out/):
void fade(uint32_t color) {
for (int i = 0; i < 255; i++) {
for (int q = 0; q < strip.numPixels(); q++) {
strip.setPixelColor(q, Wheel((color) & 255));
}
strip.setBrightness(i);
strip.show();
}
//decreasing brightness
for (int l = 255; l > 255; l--) {
for (int p = 0; p < strip.numPixels(); p++) {
strip.setPixelColor(p, Wheel((color) & 255));
}
strip.setBrightness(l);
strip.show();
}
}
The method "Wheel" is from the Arduino Neopixel strandtest example.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
Any advice on how I should go about doing it?