Neopixel Lamp - Animation Bleed Question

Hey there fellow humans,

I am currently building a lamp to get back into arduino.
The Neopixel lamp starts with a boot up sequence of 2 white pixels, which transform into two 2red pixels moving.. I want the two red pixels transition seemlessly into the mood wheel.

How can I archieve this ? I dont understand how I can change the color of the mood wheel sequence to start with red - or the movement of the 2 red pixels moving "into" the mood wheel sequence.

I appreciate any help with loooooooooove since this is the final step id like to understand for this project.

Thank you very much

#include <Adafruit_NeoPixel.h>

#define PIN            7
#define NUMPIXELS      75

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show();  // Initialize all pixels to 'off'

  int bootUpDelay = 12000 / (NUMPIXELS * 6);

  for(int j = 0; j < 6; j++) {
    for(int i = 0; i < NUMPIXELS; i++) {
      int reversePixel = NUMPIXELS - 1 - i;

      if (j == 5) {
        strip.setBrightness(255 - (6 * i / NUMPIXELS));
      }

      strip.setPixelColor(i, strip.Color(255, 255, 255));
      strip.setPixelColor(reversePixel, strip.Color(255, 255, 255));
      strip.show();
      delay(bootUpDelay);

      if (!(j == 7 && (i == NUMPIXELS - 1))) {
        strip.setPixelColor(i, strip.Color(0, 0, 0));
        strip.setPixelColor(reversePixel, strip.Color(0, 0, 0));
      }
    }
  }

  strip.setBrightness(255);
}

long firstPixelHue = 0; // Initialized to get full red from Wheel

void loop() {
  for(int i = 2; i < NUMPIXELS / 2; i++) {
    int reversePixel = NUMPIXELS - 1 - i;
    strip.setPixelColor(i, Wheel(firstPixelHue & 65535));
    strip.setPixelColor(reversePixel, Wheel(firstPixelHue & 65535));
    strip.show();
    delay(50);
  }

  for(; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
    for(int i = 0; i < strip.numPixels(); i++) {
      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
      strip.setPixelColor(i, Wheel(pixelHue & 65535));
    }
    strip.show();
    delay(100);
  }

  firstPixelHue %= 65536; // Reset hue to stay within valid range
}

uint32_t Wheel(uint16_t WheelPos) {
  if(WheelPos < 65536 / 3) {
    return strip.Color(255, WheelPos * 3 / 256, 0);
  } else if(WheelPos < 65536 * 2 / 3) {
    WheelPos -= 65536 / 3;
    return strip.Color(0, (255 - WheelPos * 2 / 256) / 4, WheelPos / 512);
  } else {
    WheelPos -= 65536 * 2 / 3;
    return strip.Color(WheelPos * 3 / 256, 0, (255 - WheelPos * 3 / 256) / 4);
  }
}

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

Do you mean... fade the solid red into the gradient of colors? How are the 75 neopixels placed? Line? Circle? Square?

Hey there! Yeah basically that the solid red of the two pixels fade into the gradient of colors, instead of the gradient of colors appearing abruptly.

The neopixels are placed in a circle.

Thank you very much!

In this loop, strip.show(); is displaying the "fade" all at one time, after all the colors have been assigned... you should move strip.show(); inside the loop so the colors are displayed as each color is assigned...

  for(; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
    for(int i = 0; i < strip.numPixels(); i++) {
      int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
      strip.setPixelColor(i, Wheel(pixelHue & 65535));
      strip.show(); // <-- HERE IT IS INSIDE THE LOOP
    }
    delay(100);
  }

This is your code in a simulation... with the one-line change...
https://wokwi.com/projects/374916699125523457

1 Like

Thanks @xfpd for providing the Wokwi simulation, that makes the idea much more "visible"!

One thing that could be removed is this if-clause in setup():

      if (!(j == 7 && (i == NUMPIXELS - 1))) {
        strip.setPixelColor(i, strip.Color(0, 0, 0));
        strip.setPixelColor(reversePixel, strip.Color(0, 0, 0));
      }

As j is controlled by this line only

for(int j = 0; j < 6; j++) {

it will never reach 7. Therefore (j == 7) will always be false and !(j == 7 && ...) will always be true. It's not very important but makes the start routine more readable.

If the brightness shall significantly drop in the last sweep (j ==5) the factor 6 in
this part in setup() might be more effective if changed to 255:

    for (int i = 0; i < NUMPIXELS; i++) {
      int reversePixel = NUMPIXELS - 1 - i;

      if (j == 5) {
        strip.setBrightness(255 - (6 * i / NUMPIXELS));
      }

Not sure if this is intented ...

Anyway I used your work on Wokwi to test the changes:

Just some suggestions ... :slight_smile:

I aimed for least effort. : )

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.