LPD8806 Programming

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

LPD8806 Programming

Postby phil007 » Fri May 18, 2012 11:09 am

How would I program a color wipe beginning in the center of the LED strip, wiping the new color to both ends?

ColorWipeFromCenter 32 LED strip Example
Image



What about a color chase from the center while running it over a base color?

ColorChaseFromCenter 32 LED strip Example
Image

Thanks,
Phil
User avatar
phil007
 
Posts: 9
Joined: Wed Dec 12, 2007 8:09 pm
Location: Round Rock, TX

Re: LPD8806 Programming

Postby pburgess » Fri May 18, 2012 11:47 am

Something close to this should work. Haven't tested, heading out the door to Maker Faire...

Code: Select all
  int i;
  uint32_t c;

  // Set all pixels to red
  c = Color(255, 0, 0);
  for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
  }
  strip.show();
  delay(100);

  // Wipe from middle:
  c = Color(255, 255, 255); // white
  for (i=strip.numPixels() / 2 - 1; i >= 0; i--) { // half of strip, count down to 0
    strip.setPixelColor(i, c); // left pixel
    strip.setPixelColor(strip.numPixels() - 1 - i, c); // right pixel
    strip.show();
    delay(100);
  }
User avatar
pburgess
 
Posts: 1327
Joined: Sun Oct 26, 2008 1:29 am

Re: LPD8806 Programming

Postby phil007 » Fri May 18, 2012 12:50 pm

I'm missing something here and get the error expected constructor, destructor, or type conversion before '=' token.

Code: Select all
#include "LPD8806.h"
#include "SPI.h"

int dataPin = 2;   
int clockPin = 3;
const int numPixels = 32;

LPD8806 strip = LPD8806(32, dataPin, clockPin);

      int i;
      uint32_t c;


      // Set all pixels to red
      c = Color(255,0,0);
      for (i=0; i < strip.numPixels(); i++) {
          strip.setPixelColor(i, c);
      }
      strip.show();
      delay(100);

      // Wipe from middle:
      c = Color(255, 255, 255); // white
      for (i=strip.numPixels() / 2 - 1; i >= 0; i--) { // half of strip, count down to 0
        strip.setPixelColor(i, c); // left pixel
        strip.setPixelColor(strip.numPixels() - 1 - i, c); // right pixel
        strip.show();
        delay(100);
      }
User avatar
phil007
 
Posts: 9
Joined: Wed Dec 12, 2007 8:09 pm
Location: Round Rock, TX

Re: LPD8806 Programming

Postby adafruit_support_bill » Fri May 18, 2012 1:44 pm

The code posted by pburgess is not a complete program. It is just an example of how to make colors 'wipe' from the middle.

If you paste that code into your 'void loop()' function it will color the strip red, then wipe white from the middle. You can expand on that by copying the second 'for' loop and changing the colors.
User avatar
adafruit_support_bill
 
Posts: 15916
Joined: Sat Feb 07, 2009 9:11 am

Re: LPD8806 Programming

Postby phil007 » Fri May 18, 2012 3:49 pm

Now the center wipe is working. Thanks for your help.

Phil

Code: Select all
#include "LPD8806.h"
#include "SPI.h"

int dataPin = 2;   
int clockPin = 3;
const int numPixels = 32;

LPD8806 strip = LPD8806(32, dataPin, clockPin);


void setup()

{
  // Start up the LED strip
  strip.begin();
}


void loop() {
  int i;
  uint32_t c;

  c = strip.Color(255, 0, 0); // red
  for (i=strip.numPixels() / 2 - 1; i >= 0; i--) { // half of strip, count down to 0
    strip.setPixelColor(i, c); // left pixel
    strip.setPixelColor(strip.numPixels() - 1 - i, c); // right pixel
    strip.show();
    delay(100);
  }


  c = strip.Color(255, 255, 255); // white
  for (i=strip.numPixels() / 2 - 1; i >= 0; i--) { // half of strip, count down to 0
    strip.setPixelColor(i, c); // left pixel
    strip.setPixelColor(strip.numPixels() - 1 - i, c); // right pixel
    strip.show();
    delay(100);
  }


  c = strip.Color(0, 0, 255); // blue
  for (i=strip.numPixels() / 2 - 1; i >= 0; i--) { // half of strip, count down to 0
    strip.setPixelColor(i, c); // left pixel
    strip.setPixelColor(strip.numPixels() - 1 - i, c); // right pixel
    strip.show();
    delay(100);
  }         


  c = strip.Color(0, 255, 0); // green
  for (i=strip.numPixels() / 2 - 1; i >= 0; i--) { // half of strip, count down to 0
    strip.setPixelColor(i, c); // left pixel
    strip.setPixelColor(strip.numPixels() - 1 - i, c); // right pixel
    strip.show();
    delay(100);
  }           
}

User avatar
phil007
 
Posts: 9
Joined: Wed Dec 12, 2007 8:09 pm
Location: Round Rock, TX

Re: LPD8806 Programming

Postby phil007 » Tue May 22, 2012 10:52 pm

ColorChaseFromCenter is almost working. I'm having an issue with the first LED on right half from center blinking white and the ends of the strip working correctly. See an example in this video. http://www.youtube.com/watch?v=BhmFr-WAhoQ

Do you know what I need to change to correct it?

Code: Select all
void setup()

{
  // Start up the LED strip
  strip.begin();
}

void loop() {
  int i;
  uint32_t c;
  uint32_t b;

  c = strip.Color(200, 200, 200); // white - running color
  b = strip.Color(255, 0, 0); // red - background color
 
  for (i=strip.numPixels() / 2 - 1; i >= 0; i--) { // half of strip, count down to 0
    strip.setPixelColor(i, c); // left pixel
    strip.setPixelColor(i + 1, b); // left pixel
    strip.setPixelColor(strip.numPixels() - 1 - i, c); // right pixel
    strip.setPixelColor(strip.numPixels() - 2 - i, b); // right pixel
    strip.show();
    delay(25);
  }
}


Image

Thanks,
Phil
User avatar
phil007
 
Posts: 9
Joined: Wed Dec 12, 2007 8:09 pm
Location: Round Rock, TX

Re: LPD8806 Programming

Postby adafruit_support_rick » Wed May 23, 2012 8:23 am

You want to analyze the math in your loop, I think. Your lights aren't doing what you want at the start and end of the loop. Everything in between seems to work correctly, right?
What you want to do is go through and do the math to see which lights are changed the first time through the loop and then again to see which lights are changed the last time through.

If you've got 32 lights, then the first time thru your loop does this:

i=strip.numPixels() / 2 - 1 = 32/2 - 1 = 15
strip.setPixelColor(i, c); i = 15 -> set 15 to white
strip.setPixelColor(i + 1, b); i + 1 = 16 -> set 16 to red
strip.setPixelColor(strip.numPixels() - 1 - i, c); 32 - 1 - 15 = 16 -> set 16 to white
strip.setPixelColor(strip.numPixels() - 2 - i, b); 32 - 2 - 15 = 15 -> set 15 to red

The last time thru, it does this

i >= 0 = 0
strip.setPixelColor(i, c); i = 0 -> set 0 to white
strip.setPixelColor(i + 1, b); i + 1 = 1 -> set 1 to red
strip.setPixelColor(strip.numPixels() - 1 - i, c); 32 - 1 - 0 = 31 -> set 31 to white
strip.setPixelColor(strip.numPixels() - 2 - i, b); 32 - 2 - 0 = 30 -> set 30 to red

How does this compare with what you're seeing when you run your sketch? With this sort of analysis, you ought to be able to figure out how to modify your loop so it gives you what you want.
User avatar
adafruit_support_rick
 
Posts: 2864
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: LPD8806 Programming

Postby phil007 » Wed May 23, 2012 3:14 pm

I fixed the end of loop error and added an IF statement to fix the second error.

Code: Select all
void loop() {
  int i;
  uint32_t c;
  uint32_t b;

  c = strip.Color(200, 200, 200); // white - running color
  b = strip.Color(255, 0, 0);     // red - background color
 
  for (i=strip.numPixels() / 2 - 1; i >= -1; i--) { // half of strip, count down to 0
    strip.setPixelColor(i, c);     // left pixel
    strip.setPixelColor(i + 1, b); // left pixel
    strip.setPixelColor(strip.numPixels() - 1 - i, c); // right pixel
  if (i < 15) strip.setPixelColor(strip.numPixels() - 2 - i, b); // right pixel
    strip.show();
    delay(25);
  }
}

Thanks for helping me along on learning how to program this strip. I just ordered another 2 meters that will be going on a larger flying wing. This 1 meter strip will be flying after a few more patterns are programmed.

Phil
User avatar
phil007
 
Posts: 9
Joined: Wed Dec 12, 2007 8:09 pm
Location: Round Rock, TX



Return to Glowy things (LCD, LED, TFT, EL) purchased at Adafruit

Who is online

Users browsing this forum: No registered users and 3 guests

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


New Products [105]

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[108]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[69]
 
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]