NeoPixel Digital RGB LED Brightest / Fade

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

NeoPixel Digital RGB LED Brightest / Fade

Postby anakinjay » 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

Postby adafruit_support_bill » 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
  for (int i = 255; i > 0; i--)
  {
      strip.setPixelColor(0, color(i,i,i));
      strip.show();
      delay(10);
  }
User avatar
adafruit_support_bill
 
Posts: 16017
Joined: Sat Feb 07, 2009 9:11 am

Re: NeoPixel Digital RGB LED Brightest / Fade

Postby Capeman » 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

Postby adafruit_support_bill » 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
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: 16017
Joined: Sat Feb 07, 2009 9:11 am

Re: NeoPixel Digital RGB LED Brightest / Fade

Postby Snakin » 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!.'.
Snakin
 
Posts: 6
Joined: Wed Feb 27, 2013 12:59 pm

Re: NeoPixel Digital RGB LED Brightest / Fade

Postby adafruit_support_bill » 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
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: 16017
Joined: Sat Feb 07, 2009 9:11 am

Re: NeoPixel Digital RGB LED Brightest / Fade

Postby Snakin » Mon Mar 11, 2013 1:47 pm

Thanks so much!.'.
Snakin
 
Posts: 6
Joined: Wed Feb 27, 2013 12:59 pm


Return to General Project help

Who is online

Users browsing this forum: mibignistinly and 13 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]