Go Down

Topic: LPD6803 LED Strip Help? (Read 4 times) previous topic - next topic

Solidus

I am extremely new to the world of Arduino but quite pleased with the potential. What i need help with is mostly advice either what to look for or just generally be pointed in the right direction. I am using a code from "Bliptronics.com Ben Moyes 2009" specifically pertaining to the LPD6803 IC, my problem is that there seems to be very limited examples of code to this IC. This code has 3 color modes, color wipe which is very easy to modify, a very nice rainbow which i still haven't deciphered yet, and a rainbow cycle (same as before) here is the code in question

Code: [Select]
#include <TimerOne.h>
#include "LPD6803.h"

//Example to control LPD6803-based RGB LED Modules in a strand
// Original code by Bliptronics.com Ben Moyes 2009
//Use this as you wish, but please give credit, or at least buy some of my LEDs!

// Code cleaned up and Object-ified by ladyada, should be a bit easier to use

/*****************************************************************************/

// Choose which 2 pins you will use for output.
// Can be any valid output pins.
int dataPin = 2;       // 'yellow' wire
int clockPin = 3;      // 'green' wire
// Don't forget to connect 'blue' to ground and 'red' to +5V

// Timer 1 is also used by the strip to send pixel clocks

// Set the first variable to the NUMBER of pixels. 20 = 20 pixels in a row
LPD6803 strip = LPD6803(200, dataPin, clockPin);


void setup() {
 
  // The Arduino needs to clock out the data to the pixels
  // this happens in interrupt timer 1, we can change how often
  // to call the interrupt. setting CPUmax to 100 will take nearly all all the
  // time to do the pixel updates and a nicer/faster display,
  // especially with strands of over 100 dots.
  // (Note that the max is 'pessimistic', its probably 10% or 20% less in reality)
 
  strip.setCPUmax(100);  // start with 50% CPU usage. up this if the strand flickers or is slow
 
  // Start up the LED counter
  strip.begin();

  // Update the strip, to start they are all 'off'
  strip.show();
}


void loop() {
  // Some example procedures showing how to display to the pixels
 
  colorWipe(Color(63, 0, 0), 90);
  colorWipe(Color(0, 63, 0), 90);
  colorWipe(Color(0, 0, 63), 90);

  rainbow(50);

  rainbowCycle(50);
}

void rainbow(uint8_t wait) {
  int i, j;
   
  for (j=0; j < 96 * 9; j++) {     // 9 cycles of all 96 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel( (i + j) % 96));
    } 
    strip.show();   // write all the pixels out
    delay(wait);
  }
}

// Slightly different, this one makes the rainbow wheel equally distributed
// along the chain
void rainbowCycle(uint8_t wait) {
  int i, j;
 
  for (j=0; j < 96 * 5; j++) {     // 5 cycles of all 96 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      // tricky math! we use each pixel as a fraction of the full 96-color wheel
      // (thats the i / strip.numPixels() part)
      // Then add in j which makes the colors go around per pixel
      // the % 96 is to make the wheel cycle around
      strip.setPixelColor(i, Wheel( ((i * 96 / strip.numPixels()) + j) % 96) );
    } 
    strip.show();   // write all the pixels out
    delay(wait);
  }
}

// fill the dots one after the other with said color
// good for testing purposes
void colorWipe(uint16_t c, uint8_t wait) {
  int i;
 
  for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

/* Helper functions */

// Create a 15 bit color value from R,G,B
unsigned int Color(byte r, byte g, byte b)
{
  //Take the lowest 5 bits of each value and append them end to end
  return( ((unsigned int)g & 0x1F )<<10 | ((unsigned int)b & 0x1F)<<5 | (unsigned int)r & 0x1F);
}

//Input a value 0 to 127 to get a color value.
//The colours are a transition r - g -b - back to r
unsigned int Wheel(byte WheelPos)
{
  byte r,g,b;
  switch(WheelPos >> 5)
  {
    case 0:
      r=31- WheelPos % 32;   //Red down
      g=WheelPos % 32;      // Green up
      b=0;                  //blue off
      break;
    case 1:
      g=31- WheelPos % 32;  //green down
      b=WheelPos % 32;      //blue up
      r=0;                  //red off
      break;
    case 2:
      b=31- WheelPos % 32;  //blue down
      r=WheelPos % 32;      //red up
      g=0;                  //green off
      break;
  }
  return(Color(r,g,b));
}

   
   


Any help would be much appreciated. My end goal is to try and have my LED strips Strobe to music and hopefully have push button light mode change, very standard from what i understand but very difficult so far.
I have read that there is a plugin for winamp to send frequency serial to arduino? if there is anyone knows of this either i would love to know about it. thank you.

Cranium

Here are a few functions for ya that I wrote for a LPD8806 project....but you will need to remove references to digitalRead(button) and butPush as these are used to detect a button press and change modes.
Code: [Select]
void music(int all){
 micLevel = ((analogRead(A0)+analogRead(A2)))%1024; //read the pot value and add it to the microphone value to allow color shifting
 if (digitalRead(button)) butPush = 1;   //Was the button pushed to change modes?
 //colorLevel = (micLevel%768)/2;
 colorLevel = micLevel%384; //adjust colorLevel with the color wheel spectrum
 numLeds = map(micLevel,200,600,0,stripSize); //Adjust adjust the most use of LEDs
 
 if (all) numLeds = stripSize;
 for (int i = 0; i < numLeds; i++){
   strip.setPixelColor(i, Wheel((i+colorLevel)%384));
 }  
 delay(map(analogRead(A1),0,1024,0,250));
 strip.show();
   for (int i=0; i < strip.numPixels(); i++) {
     strip.setPixelColor(i, 0);  // turn all pixels off
   }
 if (digitalRead(button)) butPush = 1;   //Was the button pushed to change modes?

}

Code: [Select]
void xmas(int dly){
 int color=0;
 while (butPush==0){
   for (int i=0; i<stripSize; i++){
     if (digitalRead(button)==1) {butPush=1; i=stripSize;}
     if (color==4){
       strip.setPixelColor(i,127,127,127); //white
     }
     else if (color==3){
       strip.setPixelColor(i,127,90,0); //yellow
     }
     else if (color==2){
       strip.setPixelColor(i,0,0,127); //blue
     }
     else if (color==1){
       strip.setPixelColor(i,0,127,0); //green
     }
     else {
       strip.setPixelColor(i,127,0,0); //red
     }
     if (color++==4) color=0;
   }
   if (butPush==0){
     strip.show();
     delay(dly);
   }
 }
}

Code: [Select]
void rand2(int dly){
 //turn on lights one at a time with the same random color
 //ensure that a light is turned on each cycle
 //then turn off the lights 2 at a time
 int lights[stripSize];
 for (int i=0; i<stripSize; i++) lights[i]=0;
 while (digitalRead(button)==0){
   int red = random()%128;
   int green = random()%128;
   int blue = random()%128;
   for (int i = 0; i < stripSize; i++){
     int turnon=0;
     while (turnon==0){
       if (digitalRead(button)==1) {i=stripSize; butPush=1;}
       int x = random()%stripSize;
       if (lights[x]==0){
         turnon=1;
         lights[x]=1;
         strip.setPixelColor(x,red,green,blue);
         strip.show();
       }
     }
   if (butPush==0) delay(dly);
   }
 if (butPush==0)   delay(2000);
   for (int i = 0; i < stripSize; i++){
     int turnoff=1;
     while (turnoff==1){
       if (digitalRead(button)==1) {i=stripSize; butPush=1;}
       int x = random()%stripSize;
       if (lights[x]==1){
         turnoff=0;
         lights[x]=0;
         strip.setPixelColor(x,0,0,0);
         strip.show();
       }
     }
   if (butPush==0) delay(dly);
   }
 }
}

Code: [Select]
void circlinglights(int dly){
 int b=0;
 int r=63;
 while (digitalRead(button)==0){
   strip.setPixelColor(b,0,0,2);
   strip.setPixelColor((b+1)%stripSize,0,0,9);
   strip.setPixelColor((b+2)%stripSize,0,0,16);
   strip.setPixelColor((b+3)%stripSize,0,0,40);
   strip.setPixelColor((b+4)%stripSize,0,0,55);
   strip.setPixelColor((b+5)%stripSize,0,0,80);
   strip.setPixelColor((b+6)%stripSize,0,0,127);
   strip.setPixelColor(r,2,0,0);
   strip.setPixelColor((r+stripSize-1)%stripSize,9,0,0);
   strip.setPixelColor((r+stripSize-2)%stripSize,16,0,0);
   strip.setPixelColor((r+stripSize-3)%stripSize,40,0,0);
   strip.setPixelColor((r+stripSize-4)%stripSize,55,0,0);
   strip.setPixelColor((r+stripSize-5)%stripSize,80,0,0);
   strip.setPixelColor((r+stripSize-6)%stripSize,127,0,0);
   strip.show();
   delay(dly);
   strip.setPixelColor(b,0);
   strip.setPixelColor(r,0);
   strip.show();
   if (b++==stripSize) b=0;
   if (r--==0) r=stripSize-1;
 }
 butPush = 1;
}

Solidus

Awesome, this looks like just what i needed (hopefully) is there any chance you would mind partially explaining what you have here? like i noticed there is micLevel, is this a microphone input? and if so what pins do you have it to in what orientation. and as for the button push i would like to know roughly how that is set up too because i would love to have a button push mode change and music response. thank you very much for the help you have already provided.

Cranium

The button is just a push switch that will bring pin 8 high in my case.  One side goes to +5, the other goes to pin 8 and also has a 10k resistor pulling it to ground.

The microphone is merely a sound sensor.  I picked up a couple off of eBay. 
http://www.ebay.com/itm/180625274609?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649
http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=160675056186

It has a +5 wire, ground wire, and sound level wire that I put on one of the analog inputs.  I had also set up two pots on inputs to adjust a color shift and to adjust the baseline level of what was sensed.  One mode changes the colors on the strip based on sound level and the other mode is more like a sound level meter.

brucethehoon

TRUST ME.  Go get the fast SPI library.  Just google it. It drives 6803 based strips faster and easier than other libs!

Solidus

Thank you very much Cranium i will definitely be fooling around with this to see what i can come up with. As far as the fast SPI library goes i can't seem to get it to function and am not quite sure what it is i am doing wrong, here is the example code i am trying to use
Code: [Select]
#include <FastSPI_LED.h>

#define NUM_LEDS 150

// Sometimes chipsets wire in a backwards sort of way
struct CRGB { unsigned char b; unsigned char r; unsigned char g; };
// struct CRGB { unsigned char r; unsigned char g; unsigned char b; };
struct CRGB *leds;

#define PIN 4

void setup()
{
  FastSPI_LED.setLeds(NUM_LEDS);
  FastSPI_LED.setChipset(CFastSPI_LED::SPI_LPD6803);
  //FastSPI_LED.setChipset(CFastSPI_LED::SPI_HL1606);
  //FastSPI_LED.setChipset(CFastSPI_LED::SPI_595);
  //FastSPI_LED.setChipset(CFastSPI_LED::SPI_WS2801);

  FastSPI_LED.setPin(PIN);
 
  FastSPI_LED.init();
  FastSPI_LED.start();

  leds = (struct CRGB*)FastSPI_LED.getRGBData();
}

void loop() {
  // one at a time
  for(int j = 0; j < 3; j++) {
    for(int i = 0 ; i < NUM_LEDS; i++ ) {
      memset(leds, 0, NUM_LEDS * 3);
      switch(j) {
        case 0: leds[i].r = 255; break;
        case 1: leds[i].g = 255; break;
        case 2: leds[i].b = 255; break;
      }
      FastSPI_LED.show();
      delay(10);
    }
  }

  // growing/receeding bars
  for(int j = 0; j < 3; j++) {
    memset(leds, 0, NUM_LEDS * 3);
    for(int i = 0 ; i < NUM_LEDS; i++ ) {
      switch(j) {
        case 0: leds[i].r = 255; break;
        case 1: leds[i].g = 255; break;
        case 2: leds[i].b = 255; break;
      }
      FastSPI_LED.show();
      delay(10);
    }
    for(int i = NUM_LEDS-1 ; i >= 0; i-- ) {
      switch(j) {
        case 0: leds[i].r = 0; break;
        case 1: leds[i].g = 0; break;
        case 2: leds[i].b = 0; break;
      }
      FastSPI_LED.show();
      delay(1);
    }
  }
 
  // Fade in/fade out
  for(int j = 0; j < 3; j++ ) {
    memset(leds, 0, NUM_LEDS * 3);
    for(int k = 0; k < 256; k++) {
      for(int i = 0; i < NUM_LEDS; i++ ) {
        switch(j) {
          case 0: leds[i].r = k; break;
          case 1: leds[i].g = k; break;
          case 2: leds[i].b = k; break;
        }
      }
      FastSPI_LED.show();
      delay(3);
    }
    for(int k = 255; k >= 0; k--) {
      for(int i = 0; i < NUM_LEDS; i++ ) {
        switch(j) {
          case 0: leds[i].r = k; break;
          case 1: leds[i].g = k; break;
          case 2: leds[i].b = k; break;
        }
      }
      FastSPI_LED.show();
      delay(3);
    }
  }
}

i have the library installed correctly but now i have an error code saying

In file included from testleds.cpp:6:
F:\New folder\arduino-1.0\hardware\arduino\cores\arduino/Arduino.h:199: error: default argument given for parameter 3 of 'long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)'
F:\New folder\arduino-1.0\hardware\arduino\cores\arduino/Arduino.h:108: error: after previous specification in 'long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)'
testleds.cpp: In function 'void setup()':
testleds.pde:-1: error: no matching function for call to 'CFastSPI_LED::setPin(int)'
F:\New folder\arduino-1.0\libraries\FastSPI_LED/FastSPI_LED.h:127: note: candidates are: void CFastSPI_LED::setPin(int, int, int)

the more i try and decipher it the more i just seem to get myself into trouble

Solidus

I have Tried seeing if the values i am looking for lie in FastSPI_LED.h or wiring.h or wprogram.h but i can't seem to find anything but

; unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout) in Wiring.h and i am not sure exactally what is wrong with this statement but my error pops up as

F:\New folder\arduino-1.0\hardware\arduino\cores\arduino/Arduino.h:199: error: default argument given for parameter 3 of 'long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)'
F:\New folder\arduino-1.0\hardware\arduino\cores\arduino/Arduino.h:108: error: after previous specification in 'long unsigned int pulseIn(uint8_t, uint8_t, long unsigned int)'

as to what that refers to i am lost. still digging into this, but i am getting slightly discouraged with no progress.

Solidus

If it helps at all i am using an uno smd eddition

Cranium

Wish I could help with that but I haven't used that library and am not familiar with it.  The library I used for my strip was here: https://github.com/adafruit/LPD8806

The strip I had on hand is now in production on a wheelchair so I can't test out that library with mine.

Solidus

No problem, Thanks anyway i appreciate all the help so far. still no real success on the coding front, but i am doing a lot of reading to try and educate myself some more (when i have the time that is) but i hope you don't mind if i bug you in the future Cranium as to your switching button and audio response. thanks again.

Go Up