NeoPixel Digital RGB LED Brightest / Fade
Moderators: adafruit_support_bill, adafruit

NeoPixel Digital RGB LED Brightest / Fade

by anakinjay on Wed Jan 16, 2013 10:08 pm

Just got my led strip (http://adafruit.com/products/1138) , and love it... hooked everything up to my arduino mega using the library at https://github.com/adafruit/Adafruit_NeoPixel

I can't figure out how to fade the brightness of leds though, only changing the color at full brightness.

I'd like to create a fading effect where the led fades to off, then slowly fades to full brightness, then back.... Can anyone help me out with this? Thanks in advance!!
anakinjay
 
Posts: 4
Joined: Mon Jan 07, 2013 3:28 pm

Re: NeoPixel Digital RGB LED Brightest / Fade

by adafruit_support_bill on Thu Jan 17, 2013 5:52 am

To fade, just decrease the value of the R, G and B values. For example: This should fade pixel 0 from white to black.

Code: Select all | TOGGLE FULL SIZE
  for (int i = 255; i > 0; i--)
  {
      strip.setPixelColor(0, color(i,i,i));
      strip.show();
      delay(10);
  }
User avatar
adafruit_support_bill
 
Posts: 29026
Joined: Sat Feb 07, 2009 9:11 am

Re: NeoPixel Digital RGB LED Brightest / Fade

by Capeman on Thu Feb 14, 2013 7:10 am

Hi there, how can i make the strip fade from one color into another?

I know there is the color wheel, but i cant figure out how to set it up to just fade from red to blue!

Andy
Capeman
 
Posts: 1
Joined: Thu Feb 14, 2013 7:00 am

Re: NeoPixel Digital RGB LED Brightest / Fade

by adafruit_support_bill on Thu Feb 14, 2013 8:57 am

This is the formula. There is room for optimization if you are looking for performance.

Code: Select all | TOGGLE FULL SIZE
for(int i = 0; i < n; i++) // larger values of 'n' will give a smoother/slower transition.
{
   Rnew = Rstart + (Rend - Rstart) * i / n;
   Gnew = Gstart + (Gend - Gstart) * i / n;
   Bnew = Bstart + (Bend - Bstart) * i / n;
 // set pixel color here
}
User avatar
adafruit_support_bill
 
Posts: 29026
Joined: Sat Feb 07, 2009 9:11 am

Re: NeoPixel Digital RGB LED Brightest / Fade

by Snakin on Sun Mar 10, 2013 2:15 pm

Hi folks. The initial example above makes sense in of itself, but I am a completely new Arduino user, so please tell me what goes around the code. I can't seem to paste it into any of the example sketches without getting a compile error. Much appreciated!.'.
User avatar
Snakin
 
Posts: 13
Joined: Wed Feb 27, 2013 12:59 pm
Location: Nu Venus Island.'.

Re: NeoPixel Digital RGB LED Brightest / Fade

by adafruit_support_bill on Sun Mar 10, 2013 3:49 pm

If you download the neopixel library: https://github.com/adafruit/Adafruit_NeoPixel
and open one of the examples, it will have all the basic code structure you need. What is inside the "loop()" function is what you can modify to alter the patterns. To run the example above, just clean out everything in the loop function and drop it in:

Code: Select all | TOGGLE FULL SIZE
void loop()
{
  for (int i = 255; i > 0; i--)
  {
      strip.setPixelColor(0, color(i,i,i));
      strip.show();
      delay(10);
  }
}
User avatar
adafruit_support_bill
 
Posts: 29026
Joined: Sat Feb 07, 2009 9:11 am

Re: NeoPixel Digital RGB LED Brightest / Fade

by Snakin on Mon Mar 11, 2013 1:47 pm

Thanks so much!.'.
User avatar
Snakin
 
Posts: 13
Joined: Wed Feb 27, 2013 12:59 pm
Location: Nu Venus Island.'.

Re: NeoPixel Digital RGB LED Brightest / Fade

by martinharding on Tue Oct 08, 2013 8:52 pm

I'm trying to achieve a similar effect (fade from white to dark), but having trouble with these examples. Notably the last one where it's suggested to replace everything in void loop in one of the example sketches included with the NeoPixel library (I'm using the strandtest example, which works beautifully when unedited) throws up this error with the code above:
Code: Select all | TOGGLE FULL SIZE
'color' was not defined in this scope
strandtest.pde: In function 'void loop()':
strandtest:24: error: 'color' was not declared in this scope


Kind of rusty with Arduino, any ideas?
martinharding
 
Posts: 1
Joined: Fri Oct 04, 2013 2:14 pm

Re: NeoPixel Digital RGB LED Brightest / Fade

by adafruit_support_bill on Wed Oct 09, 2013 4:38 am

'color' was not defined in this scope

Try "strip.Color()" In the current library, 'Color()' is a member function of the strip class.
User avatar
adafruit_support_bill
 
Posts: 29026
Joined: Sat Feb 07, 2009 9:11 am