🎁📬❄️📦Adafruit Holiday Shipping Deadlines 2019: Please place all UPS 2 Day orders by 11am Monday, December 16 📦❄️📬🎁
0

help with effects, fading into a solid color
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

help with effects, fading into a solid color

by tetsuo on Wed Nov 20, 2019 1:52 am

good evening everyone.

rookie to electronics here... feeling real overwhelmed with the amount of tutorials available online...

my goal is to have the rainbow cycle trail around the neopixel ring twice. the third time would be where the solid white color trails and completes the ring. it would then be a solid white color. it's to my understanding that you write out all the void loop values (?) first, then define everything more detailed below it

as of now, i can't really tell if the rainbow cycle trail is working (currently running everything through the tinkercad circuit simulator). i tried haphazardly combining rbw cycle and fade/trailing code together...

if there's also a more efficient way to write this please let me know. i am unsure if an array is necessary. though i do plan on adding a button into this in the future... but baby steps...

any advice is really appreciated, thank you in advance

my current sketch:
Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_NeoPixel.h"

#define PIN            9

const int FADE_LENGTH = 8;
const int FADE_SCALE  = 128;
const int RING_SIZE   = 12;

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

void setup() {
    strip.begin();
 // strip.setBrightness needed?
 // strip.show needed?
}


void loop () {
       rainbowCycle(30);
  for ( int i=0 ; i < RING_SIZE * 5 ; i++ ) {
        for ( int p=0 ; p < RING_SIZE ; p++ ) {
            strip.setPixelColor( p, 0 ); 
        }
        drawFade( i, 255, 128, 0);       
        strip.show();
        delay(70); // orig speed 35
    }
}


// works indep.
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}


// works indep.
void drawFade ( uint8_t start, uint8_t r, uint8_t g, uint8_t b ) {
    int brightness = 255;
    for ( int p=0 ; p < FADE_LENGTH ; p++ ) {
        strip.setPixelColor(
            ( start - p ) % RING_SIZE,
            strip.Color(
                ( r * brightness ) / 255,
                ( g * brightness ) / 255,
                ( b * brightness ) / 255               
            )
        );
        brightness = ( brightness * FADE_SCALE ) / 255;
    }
}

// below for rbw cycle
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

tetsuo
 
Posts: 19
Joined: Fri Oct 05, 2018 5:45 pm

Re: help with effects, fading into a solid color

by kcl1s on Wed Nov 20, 2019 8:33 am

Combining the fade and rainbow cycle that is in your code would be very difficult. The rainbow function in the new IDE strandtest example does the same pattern but uses the new strip.ColorHSV method. Since you can change the fade brightness using the value(V) element of the HSV it should be possible to get the effect you want. This section of the Neopixel guide has a section on ColorHSV https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use

Hope this helps

Fellow hobbyist
Keith

kcl1s
 
Posts: 1365
Joined: Tue Aug 30, 2016 12:06 pm

Re: help with effects, fading into a solid color

by kcl1s on Wed Nov 20, 2019 9:04 am

On a second look of these two codes I just can not get what effect you are going for. In the rainbow (cycle) the pixels are all on and different colors. What do you want to fade?

Keith

kcl1s
 
Posts: 1365
Joined: Tue Aug 30, 2016 12:06 pm

Re: help with effects, fading into a solid color

by tetsuo on Wed Nov 20, 2019 7:10 pm

hello keith,

thanks for the response. my goal was to have the complete rainbow cycle trailing. as in all the rbw colors would

here is the example i tried to replicate: https://youtu.be/_6LXKuo28M0?t=17. it's the second effect with the red ring

i don't know how to work with hsv yet so i was unsure on how to work with the code that this youtube user uploaded on his blogspot: https://www.arduinoslovakia.eu/blog/2018/4/neopixel-ring-hsv-rotujuce-kruhy?lang=en. i am using the tinkercad circuit feature right now and it doesn't support the hsv library

tetsuo
 
Posts: 19
Joined: Fri Oct 05, 2018 5:45 pm

Re: help with effects, fading into a solid color

by kcl1s on Wed Nov 20, 2019 9:14 pm

For what you are doing I would switch to the IDE so you can use the HSV. Plus it is much more fun to see this operating on physical hardware.

Keith

kcl1s
 
Posts: 1365
Joined: Tue Aug 30, 2016 12:06 pm

Re: help with effects, fading into a solid color

by kcl1s on Wed Nov 20, 2019 10:55 pm

Here is a rainbow fade chase function (like in the links) that works without HSV. I had to re-write Wheel into this function to give RGB values. It was a nice brain break.

Code: Select all | TOGGLE FULL SIZE
#include "Adafruit_NeoPixel.h"

#define PIN            9

const int FADE_LENGTH = 5;    //change from 8, seemed to much for 12 ring
const int FADE_SCALE  = 85;   //change from 128, better for 5 fade length
const int RING_SIZE   = 12;   //number of pixels on ring


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

void setup() {
  // put your setup code here, to run once:
  strip.begin();
  strip.show();
}

void loop() {
  // put your main code here, to run repeatedly:
  rainbowFadeChase(40);    //aurgument for speed smaller is faster
}

void rainbowFadeChase(int spd) {
  byte r, g, b;
  for (int x = 0; x < 256; x += 5) {  //cycle through the rainbow
    int WheelPos = x;                 //re-write of the Wheel function
    if (WheelPos < 85) {              //to get RGB values
      r = WheelPos * 3, g = 255 - WheelPos * 3, b = 0;
    } else if (WheelPos < 170) {
      WheelPos -= 85;
      r = 255 - WheelPos * 3, g = 0, b = WheelPos * 3;
    } else {
      WheelPos -= 170;
      r = 0, g = WheelPos * 3, b = 255 - WheelPos * 3;
    }
    //increment the start pixel around the ring
    for ( int start = 0 ; start < RING_SIZE ; start++ ) {
      //clear all pixels first
      for ( int c = 0 ; c < RING_SIZE ; c++ ) strip.setPixelColor( c, 0 );
      int brightness = 255;   //start pixel at full brightness
      for ( int f = 0 ; f < FADE_LENGTH ; f++ ) {   //fade FADE_LENGTH # pixels
        int curPix = start - f;                     //decrement backward
        if (curPix < 0) curPix += RING_SIZE;        //account for curPix < 0
        strip.setPixelColor(curPix, strip.Color(    //set current color/fade value
            ( r * brightness ) / 255,
            ( g * brightness ) / 255,
            ( b * brightness ) / 255)
        );
        brightness = ( brightness * FADE_SCALE ) / 255;   //fade next pixel brightness
      }
      strip.show();   //send pixel data
      delay(spd);     //delay by spd value
    }
  }
}


Keith

kcl1s
 
Posts: 1365
Joined: Tue Aug 30, 2016 12:06 pm

Re: help with effects, fading into a solid color

by tetsuo on Thu Nov 21, 2019 8:00 pm

good afternoon keith,

wow, thank you so much, i appreciate it! yes, my breadboard and trinket m0 are on the way so i can finally see everything in action...

thanks again :-)

tetsuo
 
Posts: 19
Joined: Fri Oct 05, 2018 5:45 pm

Please be positive and constructive with your questions and comments.