fade neopixel

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bror
 
Posts: 36
Joined: Sun Nov 30, 2014 5:12 pm

fade neopixel

Post by bror »

hi, is possible to apply a fade to the "simple" example provided by the Adafruit library?

Code: Select all

// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN            6

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      16

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 500; // delay for half a second

void setup() {
  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {
  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  for(int i=0;i<NUMPIXELS;i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
}

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: fade neopixel

Post by adafruit_support_mike »

Sure. The easiest way to do it would be with pixels.setBrightness(), which accepts values from 0 to 255 as input.

The one trick is that a straight fade from 0 to 255 won't look very good. The human eye sees brightness in terms of ratios rather than absolute values, so 'twice as much light' looks the same whether it's a step from 1 to 2 or from 128 to 256.

To get a smooth-looking fade you need to use the sequence 1, 2, 4, 8, 16, etc.

User avatar
bror
 
Posts: 36
Joined: Sun Nov 30, 2014 5:12 pm

Re: fade neopixel

Post by bror »

Code: Select all

void loop() {
  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  for(int i=0;i<NUMPIXELS;i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,150,0));
   pixels.setBrightness(150); // Moderately bright green color.
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
}
nothing has changed .. :(
i want this effect https://youtu.be/cqMnpVlkpUA?t=12s, the loop I think I know the problem is to do animation.

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: fade neopixel

Post by adafruit_support_mike »

Take a look at our Larson Scanner Shades tutorial: https://learn.adafruit.com/larson-scanner-shades

It produces the same kind of effect.

User avatar
bror
 
Posts: 36
Joined: Sun Nov 30, 2014 5:12 pm

Re: fade neopixel

Post by bror »

I tried to change "pos" but the animation is always the same, I inserted -2 to see if it made an animation only from below to above,
also can not figure out how to change the color because I do not find the usual pattern with set.pixelcolor (i, R, G, B)

Code: Select all

#include <Adafruit_NeoPixel.h>

#define N_LEDS  8
#define PIN     6

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

void setup() {
  strip.begin();
}

int pos = 0, dir = 1; // Position, direction of "eye"

void loop() {
  int j;

  // Draw 5 pixels centered on pos.  setPixelColor() will clip any
  // pixels off the ends of the strip, we don't need to watch for that.
  strip.setPixelColor(pos - 2, 0x100000); // Dark red
  strip.setPixelColor(pos - 1, 0x800000); // Medium red
  strip.setPixelColor(pos    , 0xFF3000); // Center pixel is brightest
  strip.setPixelColor(pos + 1, 0x800000); // Medium red
  strip.setPixelColor(pos + 2, 0x100000); // Dark red

  strip.show();
  delay(30);

  // Rather than being sneaky and erasing just the tail pixel,
  // it's easier to erase it all and draw a new one next time.
  for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);

  // Bounce off ends of strip
  pos += dir;
  if(pos < 0) {
    pos = 1;
    dir = -dir;
  } else if(pos >= strip.numPixels()) {
    pos = strip.numPixels() - 2;
    dir = -dir;
  }
}

User avatar
bror
 
Posts: 36
Joined: Sun Nov 30, 2014 5:12 pm

Re: fade neopixel

Post by bror »

could someone help me please? :(

User avatar
adafruit_support_bill
 
Posts: 88142
Joined: Sat Feb 07, 2009 10:11 am

Re: fade neopixel

Post by adafruit_support_bill »

I tried to change "pos" but the animation is always the same, I inserted -2 to see if it made an animation only from below to above,
What exactly are you trying to do?
also can not figure out how to change the color because I do not find the usual pattern with set.pixelcolor (i, R, G, B)
That is just another form of the same function. If you prefer to work with explicit RGB values, you can replace the existing setpixelcolor calls and specify whatever RGB values you like.

User avatar
bror
 
Posts: 36
Joined: Sun Nov 30, 2014 5:12 pm

Re: fade neopixel

Post by bror »

i want to replace this effect :)
https://youtu.be/cqMnpVlkpUA?t=12s

User avatar
adafruit_support_bill
 
Posts: 88142
Joined: Sat Feb 07, 2009 10:11 am

Re: fade neopixel

Post by adafruit_support_bill »

This is the part you need to change:

Code: Select all

  // Bounce off ends of strip
  pos += dir;
  if(pos < 0) {
    pos = 1;
    dir = -dir;
  } else if(pos >= strip.numPixels()) {
    pos = strip.numPixels() - 2;
    dir = -dir;
  }
You want to keep the same 'dir' and reset 'pos' to zero when it gets to the end:

Code: Select all

  // Reset at end of strip
  pos += 1;
 .if(pos >= strip.numPixels()) 
  {
    pos = 0;
  }

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”