ColorWipe for LPD8806

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

Moderators: adafruit_support_bill, adafruit

ColorWipe for LPD8806

Postby Jasonmorris » Mon Apr 30, 2012 5:31 am

Hi

I'm new at coding for Arduino and the LPD8806.

Is it possible to start a new colorwipe when a previous one hasn't completed?

I want a green colorWipe and then a red one to start before the green one has reached the end of the led strip.

Thank you in advance!
Jasonmorris
 
Posts: 9
Joined: Mon Apr 30, 2012 5:20 am

Re: ColorWipe for LPD8806

Postby adafruit_support_bill » Mon Apr 30, 2012 5:59 am

It is possible to write a function to do that.

This one takes two colors and starts the second color halfway through the first color.

Code: Select all
void colorWipe2(uint32_t c1, uint32_t c2, uint8_t wait) {
  int i;
 
  for (i=0; i < strip.numPixels()/2; i++) {
      strip.setPixelColor(i, c1);
      strip.show();
      delay(wait);
  }
  for (i=0; i < strip.numPixels()/2; i++) {
      strip.setPixelColor(i, c2);
      strip.setPixelColor(i + strip.numPixels()/2, c1);
      strip.show();
      delay(wait);
  }
  for (i=0; i < strip.numPixels()/2; i++) {
      strip.setPixelColor(i + strip.numPixels()/2, c2);
      strip.show();
      delay(wait);
  }
}
User avatar
adafruit_support_bill
 
Posts: 16634
Joined: Sat Feb 07, 2009 9:11 am

Re: ColorWipe for LPD8806

Postby Jasonmorris » Mon Apr 30, 2012 7:37 am

Thanks a lot! Looks very good.
I'm having some problem getting it to work though.
I'm working within the strandtest tutorial for the LPD8806.

it keeps saying colorWipe2 not declared, even though that has not been a problem before.
This problem only arrives after the uint32_t c1, (uint32_t c2, uint8_t wait) has been written into the code!
Jasonmorris
 
Posts: 9
Joined: Mon Apr 30, 2012 5:20 am

Re: ColorWipe for LPD8806

Postby adafruit_support_bill » Mon Apr 30, 2012 8:03 am

Try again. There was a stray character in the code I initially posted. It should be correct now.
User avatar
adafruit_support_bill
 
Posts: 16634
Joined: Sat Feb 07, 2009 9:11 am

Re: ColorWipe for LPD8806

Postby Jasonmorris » Mon Apr 30, 2012 9:23 am

Thanks again for the reply.

Sorry to be bothering again, but now it comes with the error message: too few arguments to function void colorWipe(uint32_t c1, uint32_t c2, uint8_t wait).
I can't seem to figure out what is wrong!
Jasonmorris
 
Posts: 9
Joined: Mon Apr 30, 2012 5:20 am

Re: ColorWipe for LPD8806

Postby adafruit_support_bill » Mon Apr 30, 2012 9:55 am

How are you calling it? You need to pass 2 colors and a wait time.
User avatar
adafruit_support_bill
 
Posts: 16634
Joined: Sat Feb 07, 2009 9:11 am

Re: ColorWipe for LPD8806

Postby Jasonmorris » Fri May 04, 2012 7:58 am

This is more or less the whole code! I must have misunderstood something!

int dataPin = 2;
int clockPin = 3;

// Set the first variable to the NUMBER of pixels. 32 = 32 pixels in a row
// The LED strips are 32 LEDs per meter but you can extend/cut the strip
LPD8806 strip = LPD8806(16, dataPin, clockPin);

int time = 2500;
void setup() {
// Start up the LED strip
strip.begin();

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


void loop() {
// fill the entire strip with...
colorWipe2(strip.Color(0,127,0), 2187); // green
colorWipe(strip.Color(127,0,0), 2500); // red


}

void colorWipe2(uint32_t c1, uint32_t c2, uint8_t wait) {
int i;

for (i=0; i < strip.numPixels()/2; i++) {
strip.setPixelColor(i, c1);
strip.show();
delay(2500);
}
for (i=0; i < strip.numPixels()/2; i++) {
strip.setPixelColor(i, c2);
strip.setPixelColor(i + strip.numPixels()/2, c1);
strip.show();
delay(2500);
}
for (i=0; i < strip.numPixels()/2; i++) {
strip.setPixelColor(i + strip.numPixels()/2, c2);
strip.show();
delay(2500);
}
}
Jasonmorris
 
Posts: 9
Joined: Mon Apr 30, 2012 5:20 am

Re: ColorWipe for LPD8806

Postby adafruit_support_bill » Fri May 04, 2012 8:12 am

As I said, you need to pass 2 colors to colorWipe2.

Code: Select all
void loop() {
// fill the entire strip with...
colorWipe2(strip.Color(127,0,0),strip.Color(0,127,0), 2187); // Red, then green
}
User avatar
adafruit_support_bill
 
Posts: 16634
Joined: Sat Feb 07, 2009 9:11 am

Re: ColorWipe for LPD8806

Postby Jasonmorris » Fri May 04, 2012 8:20 am

Thank you! I feel like an idiot!
Thank you for taking the time to help me!
You have helped me a lot on my project!
Jasonmorris
 
Posts: 9
Joined: Mon Apr 30, 2012 5:20 am

Re: ColorWipe for LPD8806

Postby Jasonmorris » Sun May 06, 2012 10:44 am

Sorry to bother you again. I have been playing around with the code trying to get the led-lights to move in pairs of two. Instead of moving one at a time i hope to get them to move in pairs of two.
I works fine for the first half of the defined led strip, but after that it skips every other light.
I have tried a bunch of solutions but none of them work.
I'm sure i have just missed something obvious, but if you could point me in the right direction i would be very happy.
thanks again,
Jason

Here is my code:

void loop() {
colorWipe2(strip.Color(127,0,0),strip.Color(0,127,0), 2187);
}



void colorWipe2(uint32_t c1, uint32_t c2, uint8_t wait) {
int i;

for (i=0; i < strip.numPixels()/2; i+=2) {
strip.setPixelColor(i, c1);
strip.setPixelColor(i+1, c1);
strip.show();
delay(2500);
}
for (i=0; i < strip.numPixels()/2; i+=2) {
strip.setPixelColor(i, c2);
strip.setPixelColor(i + strip.numPixels()/2, c1);
strip.setPixelColor(i + 1, c2);
strip.show();
delay(2500);
}
for (i=0; i < strip.numPixels()/2; i+=2) {
strip.setPixelColor(i + strip.numPixels()/2, c2);
strip.show();
delay(2500);
}
}
Jasonmorris
 
Posts: 9
Joined: Mon Apr 30, 2012 5:20 am

Re: ColorWipe for LPD8806

Postby adafruit_support_bill » Sun May 06, 2012 12:54 pm

There are 3 loops:
The first wipes C1 for half the strip. You modified it to do 2 pixels at a time.
The second loop wipes C1 on the second half and C2 on the first half. You only modified the C2 part to do 2 pixels at a time.
The third loop wipes C2 on the second half. You didn't modify the SetPixel code there at all.
User avatar
adafruit_support_bill
 
Posts: 16634
Joined: Sat Feb 07, 2009 9:11 am

Re: ColorWipe for LPD8806

Postby Jasonmorris » Tue May 08, 2012 8:40 am

I figured it out! Thank you for the pointers.

Now a new problem has arisen: is there any way to reverse the direction of the colorWipe?

So it runs towards the arduino board input and not away from it.

Hope you are able to help us with our project, we really appreciate it!
Jasonmorris
 
Posts: 9
Joined: Mon Apr 30, 2012 5:20 am

Re: ColorWipe for LPD8806

Postby adafruit_support_bill » Tue May 08, 2012 9:13 am

Loops can count down as well as up. For example:

Code: Select all
for (i=strip.numPixels()/2; i >= 0; i-=2)
User avatar
adafruit_support_bill
 
Posts: 16634
Joined: Sat Feb 07, 2009 9:11 am

Re: ColorWipe for LPD8806

Postby Jasonmorris » Wed May 09, 2012 7:49 am

Thank you once again. We thought that solution was too simple, but sometimes simple is better i guess.

Now a new problem has arisen.
We have tried lots of solutions, but none of them work.
We have two different 'objects' conneced to our arduino board:
1) The LPD 8806 led strip which runs the colorWipe.
2) A breadboard with 3 lightbulb leds connected to it, red, yellow, green (symbolizing a traffic signal).

We want the two objects to run simultaneously within the same loop. Right now it runs the breadboard lights first and then the colorWipe on the LPD 8806 starts. Is there any way to get them to run at the same time?

Here is our code so far:
Code: Select all
int dataPin = 2;   
int clockPin = 3;

// Set the first variable to the NUMBER of pixels. 32 = 32 pixels in a row
// The LED strips are 32 LEDs per meter but you can extend/cut the strip
LPD8806 strip = LPD8806(160, dataPin, clockPin);

// you can also use hardware SPI, for ultra fast writes by leaving out the
// data and clock pin arguments. This will 'fix' the pins to the following:
// on Arduino 168/328 thats data = 11, and clock = pin 13
// on Megas thats data = 51, and clock = 52
//LPD8806 strip = LPD8806(32);
int time = 2500;
int rod = 8;
int gul = 4;
int gron = 1;

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

  pinMode(rod, OUTPUT);   
  pinMode(gul, OUTPUT);
  pinMode(gron, OUTPUT);

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


void loop() {
colorWipe2(strip.Color(127,0,0),strip.Color(0,127,0), 500);
}


void colorWipe2(uint32_t c1, uint32_t c2, uint8_t wait) {
int i;
int x = 5;
x = 5;
//Tænder gul
digitalWrite(gul, HIGH);
delay(1000);
digitalWrite(gul, LOW);

//tænder røde
digitalWrite(rod, HIGH);
delay(8000);
digitalWrite(rod, LOW);
delay(0);

//tænder gul
digitalWrite(gul, HIGH);
delay(1000);
digitalWrite(gul, LOW);
delay(0);

if (x = 5) {
 
for (i=strip.numPixels()/2; i >= 0; i-=2) {
strip.setPixelColor(i, c2); // grøn
strip.setPixelColor(i + 1, c2); // grøn
strip.setPixelColor(i + strip.numPixels()/2, c1); //rød
strip.setPixelColor(i + (1) + strip.numPixels()/2, c1);  // rød
strip.show();
delay(wait);
}
}

//Tænder grøn
digitalWrite(gron, HIGH);
x = 15;
delay(10000);
digitalWrite(gron, LOW);
delay(0);

if (x = 15) {
for (i=strip.numPixels()/2; i >= 0; i-=2) {
strip.setPixelColor(i, c1);
strip.setPixelColor(i +1, c1);
strip.setPixelColor(i + strip.numPixels()/2, c2);
strip.setPixelColor(i + (1) + strip.numPixels()/2, c2);
strip.show();
delay(500);


Serial.begin(300);
Serial.println(x);

}
}
}


I really hope you can help us!
Jasonmorris
 
Posts: 9
Joined: Mon Apr 30, 2012 5:20 am

Re: ColorWipe for LPD8806

Postby adafruit_support_bill » Wed May 09, 2012 8:12 am

You need to define the timing for how you want the traffic light leds relative to the animation of the strip. If they need to be synchronized, it should not be difficult to write. If the traffic lights have to operate asynchronously, you will have to look into timers and/or interrupts.
User avatar
adafruit_support_bill
 
Posts: 16634
Joined: Sat Feb 07, 2009 9:11 am

Next

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

Who is online

Users browsing this forum: Google [Bot], GTBecker and 9 guests

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


New Products [114]

Raspberry Pi[82]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
BeagleBone[23]
 
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[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


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