2x RGB LED Stripes at the same time

by lakredo on Wed Mar 13, 2013 12:44 pm

Hi,

is it possible to control two Stripes at the same time?
For example:

Code: Select all
if (digitalRead(Taster1)==HIGH)     //Wenn Taster 1 HIGH
  int p; 
  for (p=0; p<1; p++){ 
  colorWipe1(strip1.Color(0,0,127), 255);             // blau
  colorWipe2(strip2.Color(0,0,127), 255);      // blau
  delay(10); 
}
for (int i=0; i<100; i++){
  colorDot1(strip1.Color(5,50,127),255);                      // türkis
  colorDot2(strip2.Color(5,50,127),255);                   // türkis

 }


All 4 Codes work fine on its own. But in the second "for-loop" the last pixel (Strip1) is "HIGH" and stops until the other code(Strip2) is over and vice versa.
Is it possible to put 2 or more codes in one big code or optimize the old code that they work at the same time?
I have also a code with 3 Stripes and want them to work at the same time.

colorWipe1 & 2

Code: Select all
void colorWipe1(uint32_t c, uint8_t wait) {
    strip1.setPixelColor(0, 0,0,127);             // setze die ersten drei Pixel auf blau
    strip1.setPixelColor(1, 0,0,127);               
    strip1.setPixelColor(2, 0,0,127);   
  int i;
 
  for (i=0; i < strip1.numPixels(); i++) {
   
      strip1.setPixelColor(i, c);
      strip1.show();
 
      delay(wait);     
  }
}


Codes colorDot1 and ColorDot2
Code: Select all
void colorDot1(uint32_t c, uint8_t wait) {

  int r;

  for (r=3; r < strip1.numPixels(); r++) {
      strip1.setPixelColor(r, c);
      if (r == 3) {
       strip1.setPixelColor(strip1.numPixels()-1, 0,0,127);
      } else {
        strip1.setPixelColor(r-1, 0,0,127);
      }
     
      zaehl1++;
      Serial.println(zaehl1);
      if (zaehl1>63) {strip1.setPixelColor(0, 0,0,0);}
      else {strip1.setPixelColor(0, 0,0,127);}
      if (zaehl1>90) {strip1.setPixelColor(1, 0,0,0);}
         else {strip1.setPixelColor(1, 0,0,127);}
      if (zaehl1>180) {strip1.setPixelColor(2, 0,0,0);}
       else {strip1.setPixelColor(2, 0,0,127);}
        strip1.show();
      delay(wait);
  }

}

//  colorDot2
void colorDot2(uint32_t c, uint8_t wait) {
  int r;
 
  int fill2=fill+1;
  for (r=0; r < strip2.numPixels()-fill; r++) {
      strip2.setPixelColor(r, c);
      if (r == 0) {
       strip2.setPixelColor(strip2.numPixels()-fill2, 0,0,127);
     
     if (fill>0) {fill--;} 
 
      } else {
        strip2.setPixelColor(r-1, 0,0,127);
      }
      strip2.show();
      delay(wait);
  }
}



Sorry for my English, but I`m from Germany ;-)

Greetz lakredo
lakredo
 
Posts: 7
Joined: Wed Mar 13, 2013 12:15 pm

Re: 2x RGB LED Stripes at the same time

by adafruit_support_bill on Wed Mar 13, 2013 1:32 pm

If you have 3 identical strips and want them to all display the same thing, you can just define 1 strip in your code and connect all the data lines together
User avatar
adafruit_support_bill
 
Posts: 25601
Joined: Sat Feb 07, 2009 9:11 am

Re: 2x RGB LED Stripes at the same time

by lakredo on Wed Mar 13, 2013 1:38 pm

Thanks for the answer.
But is it possible that 3 stripes display 3 different codes at the same time?
Last edited by lakredo on Wed Mar 13, 2013 1:46 pm, edited 1 time in total.
lakredo
 
Posts: 7
Joined: Wed Mar 13, 2013 12:15 pm

Re: 2x RGB LED Stripes at the same time

by adafruit_support_bill on Wed Mar 13, 2013 1:46 pm

It should be possible. Which strips are you using?
User avatar
adafruit_support_bill
 
Posts: 25601
Joined: Sat Feb 07, 2009 9:11 am

Re: 2x RGB LED Stripes at the same time

by lakredo on Wed Mar 13, 2013 1:47 pm

I use the Adafruit Stripes(LPD8806) with an Arduino MEGA.
lakredo
 
Posts: 7
Joined: Wed Mar 13, 2013 12:15 pm

Re: 2x RGB LED Stripes at the same time

by adafruit_support_bill on Wed Mar 13, 2013 1:55 pm

You should be able to do that with those strips and a Mega. How do you have them wired?

If you post your whole code - and add some comments explaining what you want it to do, we might be able to find the problem.
User avatar
adafruit_support_bill
 
Posts: 25601
Joined: Sat Feb 07, 2009 9:11 am

Re: 2x RGB LED Stripes at the same time

by lakredo on Wed Mar 13, 2013 2:40 pm

The Pinout is not exactly the same like on the picture.
The code is not yet complete, i will add codes for all 4 buttons.
I also need an interrupt code for the Buttons, but the code has priority.

I hope you understand what I want to do. :-)

Greetings lakredo

Code: Select all
#include "LPD8806.h"
#include "SPI.h"
#include <AFMotor.h>

//TASTER
int Taster1 = 50;    //Taster 1 an Pin 52
int Taster2 = 52;    //Taster 2 an Pin 50
int Taster3 = 48;    //Taster 3 an Pin 48
int Taster4 = 46;    //Taster 4 an Pin 46
//int Taster5 = 44;    //Taster 5 an Pin 44

//Taster LEDs
int LED1 = 22;       //LED von Taster 1 an Pin 22
int LED2 = 23;       //LED von Taster 2 an Pin 24
int LED3 = 24;       //LED von Taster 3 an Pin 26
int LED4 = 25;       //LED von Taster 4 an Pin 28
int LED5 = 26;       //LED von Taster 5 an Pin 30

//RGB LED Strips

//Strip 1
int dataPin1 = 30;    //Daten Pin von LED Stripe1 an Pin 30
int clockPin1 = 31;   //Clock Pin von LED Stripe1 an Pin 31

//Strip 2
int dataPin2 = 32;    //Daten Pin von LED Stripe2 an Pin 32
int clockPin2 = 33;   //Clock Pin von LED Stripe2 an Pin 33

//Strip 3
int dataPin3 = 34;    //Daten Pin von LED Stripe3 an Pin 34
int clockPin3 = 35;   //Clock Pin von LED Stripe3 an Pin 35
 
//Motoren

//Citratmotor
AF_DCMotor motorCP(1, MOTOR12_1KHZ);

//Blutmotor
AF_DCMotor motorBP(2, MOTOR12_64KHZ);

//int x=digitalRead(Taster2);

int fill=3;            //Zentrifugen Variable

int zaehl1;            //Zaehler fuer Strip1
int zaehl3=0;          //Zaehler fuer Strip3

LPD8806 strip1 = LPD8806(12, dataPin1, clockPin1);
LPD8806 strip2 = LPD8806(12, dataPin2, clockPin2);
LPD8806 strip3 = LPD8806(12, dataPin3, clockPin3);

void setup() {
  Serial.begin(9600);
  pinMode(Taster1,INPUT);         //Taster1 ist Input
  pinMode(Taster2,INPUT);         //Taster2 ist Input
  pinMode(Taster3,INPUT);         //Taster3 ist Input
  pinMode(Taster4,INPUT);         //Taster4 ist Input
  motorBP.setSpeed(255);          //Drehgeschwindigkeit Blutpumpe 255/255
  motorCP.setSpeed(255);          //Drehgeschwindigkeit Citratpumpe 255/255
 
  digitalWrite(50,LOW);           // Pin 50 auf LOW
 
  pinMode(LED1,OUTPUT);   //LED1 ist Output
  pinMode(LED2,OUTPUT);   //LED2 ist Output
 
  // Start up the LED strip
  strip1.begin();
  strip2.begin();
  strip3.begin();
  // Update the strip, to start they are all 'off'
  strip1.show();                  //Strip1 alle LED aus
  strip2.show();                  //Strip2 alle LED aus
  strip3.show();                  //Strip2 alle LED aus
  delay(10);
}
void loop() {
 
 
//TASTER 1 (Vorfüllung) HIGH
  if (digitalRead(Taster1)==HIGH)     //Wenn Taster 1 HIGH
  {
  digitalWrite(LED1,HIGH);            //LED des Taster 1 AN
  strip1.show();   
  delay(10);
  motorCP.run(FORWARD);               //Motor CP dreht vorwärts
  motorBP.run(FORWARD);               //Motor CP dreht vorwärts
 
  int p; 
  for (p=0; p<1; p++){                                   //colorWipe one time
   colorWipe1(strip1.Color(0,0,127), 255);               //Strip 1 blau
  colorWipe2(strip2.Color(0,0,127), 255);      // Strip 2 blau
  delay(10); 
}
 for (int i=0; i<100; i++){                             //Do "ColorDot 1&2" 100 time


  colorDot1(strip1.Color(127,50,127),255);

  colorDot2(strip2.Color(127,50,127),255);
                    
 }

}

//TASTER 2 (Blutentnahme) HIGH

 if (digitalRead(Taster2)==HIGH)                   
{
  digitalWrite(LED2,HIGH); 
  strip2.show();

  delay(10);
  int p; 
  for (p=0; p<1; p++){ 
  // fill the entire strip with...
  colorWipe2(strip2.Color(127,0,0), 255);      // red
  delay(10);
 
 
  //Code
}
}
}

//Methoden

//Methoden Strip1
void colorDot1(uint32_t c, uint8_t wait) {

  int r;

  for (r=3; r < strip1.numPixels(); r++) {
      strip1.setPixelColor(r, c);
      if (r == 3) {
       strip1.setPixelColor(strip1.numPixels()-1, 0,0,127);
       
          } else {
        strip1.setPixelColor(r-1, 0,0,127);
        strip1.show();
        delay(wait);
      }
     
      zaehl1++;
      Serial.println(zaehl1);
      if (zaehl1>12) {strip1.setPixelColor(0, 0,0,0);}
      else {strip1.setPixelColor(0, 0,0,127);}
      if (zaehl1>18) {strip1.setPixelColor(1, 0,0,0);}
         else {strip1.setPixelColor(1, 0,0,127);}
      if (zaehl1>180) {strip1.setPixelColor(2, 0,0,0);}
       else {strip1.setPixelColor(2, 0,0,127);}
       
     
  }

}

// Befehle für Strip 2 (Blut bis Zentrifuge)
void colorDot2(uint32_t c, uint8_t wait) {
  int r;
 
  int fill2=fill+1;
  for (r=0; r < strip2.numPixels()-fill; r++) {
      strip2.setPixelColor(r, c);
      if (r == 0) {
       strip2.setPixelColor(strip2.numPixels()-fill2, 0,0,127);
     
     if (fill>0) {fill--;} 
 
      } else {
        strip2.setPixelColor(r-1, 0,0,127);
       
      }
      strip2.show();
   
      delay(wait);
  }
}


// Befehle für Strip 3 PLASMABEHAELTER

void colorDot3(uint32_t c, uint8_t wait) {
 
 
  int r;
 
  int fill2=fill+1;
  for (r=0; r < strip3.numPixels()-fill; r++) {
      strip3.setPixelColor(r, c);
      if (r == 0) {
       strip3.setPixelColor(strip3.numPixels()-fill2, 127,127,0);

      } else {
        strip3.setPixelColor(r-1, 127,127,0);
       
      }
      strip3.show();
      delay(wait);
      zaehl3++;
      Serial.println(zaehl3);
      if (zaehl3>30) {strip3.setPixelColor(11, 0,0,127);}
      if (zaehl3>60) {strip3.setPixelColor(10, 0,0,127);}
      if (zaehl3>270) {strip3.setPixelColor(9, 0,0,127);}
  }
}

// ColorWipe1
void colorWipe1(uint32_t c, uint8_t wait) {
    strip1.setPixelColor(0, 0,0,127);             // setze die ersten drei Pixel auf blau
    strip1.setPixelColor(1, 0,0,127);               
    strip1.setPixelColor(2, 0,0,127);   
  int i;
 
  for (i=0; i < strip1.numPixels(); i++) {
   
      strip1.setPixelColor(i, c);
      strip1.show();
 
      delay(wait);     
  }
}

//ColorWipe2
void colorWipe2(uint32_t c, uint8_t wait) {
   
  int i;
  int au = strip2.numPixels();
  for (i=0; i < au-3; i++) {
   
      strip2.setPixelColor(i, c);
      strip2.show();
 
      delay(wait);
     
  }
}


//ColorWipe3
void colorWipe3(uint32_t c, uint8_t wait) {
   
  int i;
  int au = strip3.numPixels();
  for (i=0; i < au-4; i++) {
   
      strip3.setPixelColor(i, c);
      strip3.show();
 
      delay(wait);   
  }
}
Attachments
project1.jpg
project1.jpg (138.04 KiB) Viewed 471 times
lakredo
 
Posts: 7
Joined: Wed Mar 13, 2013 12:15 pm

Re: 2x RGB LED Stripes at the same time

by adafruit_support_bill on Wed Mar 13, 2013 3:12 pm

In your colorDot1 and colorDot3, you do not have a "show()" at the end. So the last changes will not be seen.
User avatar
adafruit_support_bill
 
Posts: 25601
Joined: Sat Feb 07, 2009 9:11 am

Re: 2x RGB LED Stripes at the same time

by lakredo on Fri Mar 15, 2013 9:16 am

I have changed the code and set "show()" at the end of the code. But the last pixel still only changes when the colorDot begins again.


Here is my new code:
(all "colorDot" (1,2,3,4) are similar and when e.g. colorDot 4 runs, the last pixel of the colorDot3 and colorDot2 is still HIGH(with the wrong color ) until the program cames to the "colorDot 3 or 2" )


Code: Select all
 
if (digitalRead(Taster2)==HIGH)                   
{
  digitalWrite(LED2,HIGH); 
  strip1.show();

  delay(10);
  int p,q; 
  for (p=0; p<1; p++){ 
  // fill the entire strip with...
  colorFull2(strip1.Color(127,50,127),255);
 
 
  for (q=0; q<100; q++){
  colorDot4(strip1.Color(127,50,127),255);
  colorDot2(strip1.Color(127,50,0),255);
  colorDot3(strip2.Color(127,127,0),255);
}
}
}



Code: Select all
void colorDot2(uint32_t c, uint8_t wait) {
  int r;
 
  int fill2=fill+1;
  for (r=13; r < 33-fill; r++) {
      strip1.setPixelColor(r, c);
      if (r == 13) {
       strip1.setPixelColor(33-fill2, 127,0,0);
     
     if (fill>0) {fill--;} 
 
      } else {
        strip1.setPixelColor(r-1, 127,0,00);
       
      }
      strip1.show();
   
      delay(wait);
  }
}


// Befehle für Strip 3 PLASMABEHAELTER

void colorDot3(uint32_t c, uint8_t wait) {

  int r;
 
  int fill2=fill+1;
  for (r=0; r < strip2.numPixels()-fill; r++) {
      strip2.setPixelColor(r, c);
      if (r == 0) {
       strip2.setPixelColor(strip2.numPixels()-fill2, 127,50,0);

      } else {
        strip2.setPixelColor(r-1, 127,50,0);
       
      }
      strip2.show();
      delay(wait);
      zaehl3++;
      Serial.println(zaehl3);
      if (zaehl3>30) {strip2.setPixelColor(13, 127,50,0);}
      if (zaehl3>60) {strip2.setPixelColor(12, 127,50,0);}
      if (zaehl3>270) {strip2.setPixelColor(11, 127,50,0);}
      strip2.show();
  }
}


void colorDot4(uint32_t c, uint8_t wait) {

 int r,s;
 s= 13;
  for (r=3; r < s; r++) {
      strip1.setPixelColor(r, c);
      if (r == 3) {
       strip1.setPixelColor(s-1, 0,0,127);
       
          } else {
        strip1.setPixelColor(r-1, 0,0,127);
 delay(wait);
      }
     
      zaehl1++;
      Serial.println(zaehl1);
      if (zaehl1>30) {strip1.setPixelColor(0, 0,0,0);}
      else {strip1.setPixelColor(0, 0,0,127);}
      if (zaehl1>60) {strip1.setPixelColor(1, 0,0,0);}
      else {strip1.setPixelColor(1, 0,0,127);}
      if (zaehl1>180) {strip1.setPixelColor(2, 0,0,0);}
          else {strip1.setPixelColor(2, 0,0,127);}
       strip1.show();
       delay(wait);
             
  }
 
}


I hope you understand what the problem is.
I can also make a video of the strips so you can see it.

Greetings

lakredo
lakredo
 
Posts: 7
Joined: Wed Mar 13, 2013 12:15 pm

Re: 2x RGB LED Stripes at the same time

by adafruit_support_bill on Fri Mar 15, 2013 10:02 am

The loop logic is a little confusing, but it looks like your code handles the last pixel differently than all the rest. You set the last pixel at the beginning of your loop:
Code: Select all
  for (r=13; r < 33-fill; r++) {
      strip1.setPixelColor(r, c);
      if (r == 13) {
       strip1.setPixelColor(33-fill2, 127,0,0);


And the rest of your loop you are using "r-1", so the last pixel is never written.
Code: Select all
      } else {
        strip1.setPixelColor(r-1, 127,0,00);
       
      }
User avatar
adafruit_support_bill
 
Posts: 25601
Joined: Sat Feb 07, 2009 9:11 am

Re: 2x RGB LED Stripes at the same time

by lakredo on Fri Mar 15, 2013 11:50 am

Yes, i derived a code from http://www.adafruit.com/forums/viewtopic.php?f=47&p=161978 here.
I just want to send a pixel in a color that i set in colorDot(e.g. orange) which goes down the strip.
The color of the other pixel(e.g. red) should not be changed by the pixel.
That should be the basic code. After that I want to fill the strip with one Pixel more after every round (e.g. color red )
lakredo
 
Posts: 7
Joined: Wed Mar 13, 2013 12:15 pm

Re: 2x RGB LED Stripes at the same time

by lakredo on Sun Mar 17, 2013 3:55 pm

Finally I got it.

Code: Select all
void colorDot2(uint32_t c, uint8_t wait) {
  int r;
 
 
  for (r=13; r < strip1.numPixels()-fill; r++) {
      strip1.setPixelColor(r, c);
        strip1.show();
          delay(200);
       if (r == 13) {     
       if (fill>0)
     {fill--;}
   strip1.setPixelColor(r, 127,0,0);
 } 
     
           else {
       
   
      strip1.setPixelColor(r, 127,0,0);
           }
      strip1.show();
     
  }
}
lakredo
 
Posts: 7
Joined: Wed Mar 13, 2013 12:15 pm