LPD8806 Strip LEDs einzeln ansteuern

Hallo,
ich bin absoluter Anfänge mit Arduino.

Habe hier einen LPD8806 Strip (18 LEDs lang) und möchte die LEDs einzeln oder zusammen ansteuern und eine gewisse Zeit leuchten lassen.
Als Beispiel könnte es so aussehen:
LED1 rot, LED2 grün, Led3 blau... (leuchten 4 Sekunden)
alle LEDs rot (leuchten 3 Sekunden)
LED1,3,5,7,9,11,13,15,17 rot und LED2,4,6,8,10,12,14,16,18 blau (leuchten 5 Sekunden)
Kann mir jemand helfen dies umzusetzen?
Ich denke wenn ich diese Codezeilen hätte könnte ich alles weitere selbst davon ableiten...

Der Strandtestcode der schon läuft ist dieser:

#include "LPD8806.h"
//#include "SPI.h"

// Example to control LPD8806-based RGB LED Modules in a strip

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

// Number of RGB LEDs in strand:
int nLEDs = 18;

// Chose 2 pins for output; can be any valid output pins:
int dataPin  = 2;
int clockPin = 3;

// First parameter is the number of LEDs in the strand.  The LED strips
// are 32 LEDs per meter but you can extend or cut the strip.  Next two
// parameters are SPI data and clock pins:
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);

// You can optionally use hardware SPI for faster writes, just leave out
// the data and clock pin parameters.  But this does limit use to very
// specific pins on the Arduino.  For "classic" Arduinos (Uno, Duemilanove,
// etc.), data = pin 11, clock = pin 13.  For Arduino Mega, data = pin 51,
// clock = pin 52.  For 32u4 Breakout Board+ and Teensy, data = pin B2,
// clock = pin B1.  For Leonardo, this can ONLY be done on the ICSP pins.
//LPD8806 strip = LPD8806(nLEDs);

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...
  colorWipe(strip.Color(127,   0,   0), 50);  // Red
  colorWipe(strip.Color(  0, 127,   0), 50);  // Green
  colorWipe(strip.Color(  0,   0, 127), 50);  // Blue

  rainbow(10);
  rainbowCycle(0);  // make it go through the cycle fairly fast
}

void rainbow(uint8_t wait) {
  int i, j;
   
  for (j=0; j < 384; j++) {     // 3 cycles of all 384 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel( (i + j) % 384));
    }  
    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) {
  uint16_t i, j;
  
  for (j=0; j < 384 * 5; j++) {     // 5 cycles of all 384 colors in the wheel
    for (i=0; i < strip.numPixels(); i++) {
      // tricky math! we use each pixel as a fraction of the full 384-color wheel
      // (thats the i / strip.numPixels() part)
      // Then add in j which makes the colors go around per pixel
      // the % 384 is to make the wheel cycle around
      strip.setPixelColor(i, Wheel( ((i * 384 / strip.numPixels()) + j) % 384) );
    }  
    strip.show();   // write all the pixels out
    delay(wait);
  }
}

// Fill the dots progressively along the strip.
void colorWipe(uint32_t c, uint8_t wait) {
  int i;

  for (i=0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }
}

// Chase one dot down the full strip.
void colorChase(uint32_t c, uint8_t wait) {
  int i;

  // Start by turning all pixels off:
  for(i=0; i<strip.numPixels(); i++) strip.setPixelColor(i, 0);

  // Then display one pixel at a time:
  for(i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c); // Set new pixel 'on'
    strip.show();              // Refresh LED states
    strip.setPixelColor(i, 0); // Erase pixel, but don't refresh!
    delay(wait);
  }

  strip.show(); // Refresh to turn off last pixel
}

/* Helper functions */

//Input a value 0 to 384 to get a color value.
//The colours are a transition r - g -b - back to r

uint32_t Wheel(uint16_t WheelPos)
{
  byte r, g, b;
  switch(WheelPos / 128)
  {
    case 0:
      r = 127 - WheelPos % 128;   //Red down
      g = WheelPos % 128;      // Green up
      b = 0;                  //blue off
      break; 
    case 1:
      g = 127 - WheelPos % 128;  //green down
      b = WheelPos % 128;      //blue up
      r = 0;                  //red off
      break; 
    case 2:
      b = 127 - WheelPos % 128;  //blue down 
      r = WheelPos % 128;      //red up
      g = 0;                  //green off
      break; 
  }
  return(strip.Color(r,g,b));
}

Danke!!!

Möglicherweise hat ja auch jemand einen Link für mich wo ich selbst herausfinden kann LED1 und LED2 z.B. 5 Sekunden leuchten zu lassen.
Mit normalen LEDs bekomme ich das hin, aber da der LED-Strip ja mit clockPin und dataPin gesteuert wird, bräuchte ich einen Fingerzeig in die richtige Richtung....

Lieben Dank für eure Zeit...
Detlef

Mit normalen LEDs bekomme ich das hin, aber da der LED-Strip ja mit clockPin und dataPin gesteuert wird, bräuchte ich einen Fingerzeig in die richtige Richtung....

Du hast die Bibliothek ja bereits gefunden.

Mit strip.setPixelColor(LED_Nummer, Farbe) kannst Du jeder LED eine Farbe zuordnen. Aber erst bei einem strip.show() werden alle zuvor gemachten Änderungen angezeigt. Da Du's mit normalen LEDs hinkriegst, ist dies die einzig relevante Änderung.

Danke pylon für deine Antwort.
Ich versuche es so:

strip.setPixelColor(LED_1, 127,   0,   0); //LED rot
      strip.show();   
    delay(1000);

Kannst du mir mal ein einfaches Beispiel geben, da mit meinem code ist die Antwort "LED_1" was not declared in this scope

Hier nochmal der vollständige code:

#include "LPD8806.h"
//#include "SPI.h"

// Example to control LPD8806-based RGB LED Modules in a strip

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

// Number of RGB LEDs in strand:
int nLEDs = 18;

// Chose 2 pins for output; can be any valid output pins:
int dataPin  = 1;
int clockPin = 0;

// First parameter is the number of LEDs in the strand.  The LED strips
// are 32 LEDs per meter but you can extend or cut the strip.  Next two
// parameters are SPI data and clock pins:
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);

// You can optionally use hardware SPI for faster writes, just leave out
// the data and clock pin parameters.  But this does limit use to very
// specific pins on the Arduino.  For "classic" Arduinos (Uno, Duemilanove,
// etc.), data = pin 11, clock = pin 13.  For Arduino Mega, data = pin 51,
// clock = pin 52.  For 32u4 Breakout Board+ and Teensy, data = pin B2,
// clock = pin B1.  For Leonardo, this can ONLY be done on the ICSP pins.
//LPD8806 strip = LPD8806(nLEDs);

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

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


void loop() {

 
  // Schalte LED_1 Rot...
 strip.setPixelColor(LED_1, 127,   0,   0); //LED rot
      strip.show();   
    delay(1000);
 

}

Hallo,

ich interessiere mich auch für den "LPD8806" RGB Strip. Wie verkabelst du das denn? Gibt es da einen Stecker mit dem man an das Board dann direkt ran kann oder benötigt man noch weitere Komponenten?

Gruß Jörn

Hallo Jörn,

Plus und minus an den Arduino (oder externe 5V bei längerem Strip) und gesteuert wird er über zwei Ausgänge des Arduino (bei mir ArduinoUno Kanal 11 und 12).
Andere Komponenten brauchst du nicht.

oh, das geht ja fix. danke.

Also GND und +5V verbinden ok.
in einigen videos hab ich stecker gesehen, gibts die zu kaufen
oder hab ich da jeweils dann "marke eigenbau" gesehen?

Ok, ich habs... die Farben und einzelne LEDs sind klar:

strip.setPixelColor(0, 127,   127,   127); //LED weiß
 strip.setPixelColor(1, 127,   0,   0); //LED rot
 strip.setPixelColor(2, 0,   127,   0); //LED blau
 strip.setPixelColor(3, 0,   0,   127); //LED grün
      strip.show();

Kann ich irgendwie mehrere LEDs auf einmal schalten bzw. zusammen fassen z.B. 2.3.4. Led grün 1.5.6. Led blau?

hi,

den strip lieber mit externen 5V (kann aber das gleiche 5V-netzteil sein, mit dem der arduino vielleicht versorgt wird, sein).
LED_1 ist nicht definiert, Du mußt wirklich die nummer nehmen (1, 2, 3, usw).
die stecker gibts bei ebay, gib mal rgb strip oder 8806 ein und geh auf weltweit...

gruß stefan

Kann ich irgendwie mehrere LEDs auf einmal schalten bzw. zusammen fassen z.B. 2.3.4. Led grün 1.5.6. Led blau?

Nein, aber Du darfst eine Schleife (z.B. for(;;)) verwenden. Du kannst Dir auch Deine eigene Tool-Chain zusammenstellen, wo dann eine Funktion enthalten sein kann, die mehrere LEDs auf einen bestimmten Wert stellt. Geschaltet werden sie zusammen, wenn Du strip.show() aufrufst.

hi,

leds zusammenfassen:
einfache methode wäre,
eigene funktion mySetPixel(byte nr, byte r, byte g, byte b)
wenn nr kleiner 19
setPixelColor(nr, r, g, b)
wenn nr == 21
setPixelColor(1, r, g, b)
setPixelColor(5, r, g, b)
setPixelColor(9, r, g, b)
wenn nr == 22
setPixelColor(2, r, g, b)
setPixelColor(6, r, g, b)
setPixelColor(10, r, g, b)
und so weiter,
schau mal nach select case.

gruß stefan

@Stefan danke, sieht so aus als wäre es das was ich suche, verstehe aber noch nicht wie ich es einbaue...
Über select case habe ich leider nichts gefunden :frowning:

hi,

sorry, mein fehler, falsche programmiersprache.
switch case
http://arduino.cc/en/Reference/SwitchCase
Du kannst es auch über einzelne if's machen, switch case ist halt übersichtlicher...

gruß stefan

Danke für eure Mühe, switch case schaut mir kompliziert aus...
Aber auch mit if kriege ich es nicht hin...

#include "LPD8806.h"
//#include "SPI.h"

// Example to control LPD8806-based RGB LED Modules in a strip

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

// Number of RGB LEDs in strand:
int nLEDs = 18;

// Chose 2 pins for output; can be any valid output pins:
int dataPin  = 1;
int clockPin = 0;

// First parameter is the number of LEDs in the strand.  The LED strips
// are 32 LEDs per meter but you can extend or cut the strip.  Next two
// parameters are SPI data and clock pins:
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);


void setup() {
  
  mySetPixel(byte nr, byte r, byte g, byte b)
  
 if (nr <19){
  setPixelColor(nr, r, g, b)
  strip.show();
}
 if (nr == 21){
  setPixelColor(1, r, g, b)
  setPixelColor(5, r, g, b)
  setPixelColor(9, r, g, b)
        strip.show();
  // Start up the LED strip
  strip.begin();

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


void loop() {

        strip.setPixelColor(21, 0,   127,   0); //LED blau
        strip.show(); //Update LEDs to show the color
  delay(500);

}

Fehlermeldungen:
_2LEDFarbwechsel.ino: In function 'void setup()':
_2LEDFarbwechsel:29: error: expected primary-expression before 'nr'
_2LEDFarbwechsel:29: error: expected primary-expression before 'r'
_2LEDFarbwechsel:29: error: expected primary-expression before 'g'
_2LEDFarbwechsel:29: error: expected primary-expression before 'b'
_2LEDFarbwechsel:29: error: 'mySetPixel' was not declared in this scope
_2LEDFarbwechsel:31: error: expected ;' before 'if' _2LEDFarbwechsel:35: error: 'nr' was not declared in this scope _2LEDFarbwechsel:36: error: 'r' was not declared in this scope _2LEDFarbwechsel:36: error: 'g' was not declared in this scope _2LEDFarbwechsel:36: error: 'b' was not declared in this scope _2LEDFarbwechsel:36: error: 'setPixelColor' was not declared in this scope _2LEDFarbwechsel:37: error: expected ;' before 'setPixelColor'
_2LEDFarbwechsel:48: error: a function-definition is not allowed here before '{' token
_2LEDFarbwechsel:74: error: expected `}' at end of input

Da muss ich dem Compiler recht geben, das verstehe ich auch nicht:

  mySetPixel(byte nr, byte r, byte g, byte b)
  
 if (nr <19){

Willst du eine Funktion mySetPixel( ...) definieren ?
( Die wird aber nirgends verwendet )

  • Dann hast du in der leeren 2. Reihe ein { vergessen
  • Das geht nur ausserhalb von setup()

Willst du eine Funktion mySetPixel verwenden ?
( Die ist aber nirgends definiert )

  • Das ginge mit mySetPixel(nr, r, g, b);
  • Diese Variablen sind aber alle undefiniert.

Die Fehlermeldungen sind eigentlich ziemlich klar, ( wenn man die Zeilennummern nicht wörtlich nimmt ) oder ?
z.B. expected `;' before 'if' : Stefan hat dir nur sogenannten Pseudo-Code geliefert, die Semikolons und das "strip." vor setPixelColor sind noch dein Anteil dazu.

oh weh, ich bin so eine null... wie definiere ich denn nr, r, g, b, ?

Jetzt habe ich zwar keine Fehlermeldung mehr, aber trotzdem Fehler drin, da ich wie gesagt keine Ahnung von Arduino habe...
Bitte um Verbesserung:

#include "LPD8806.h"
//#include "SPI.h"

// Example to control LPD8806-based RGB LED Modules in a strip

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

// Number of RGB LEDs in strand:
int nLEDs = 18;
int nr; //habe ich eingefügt
int r; //habe ich eingefügt
int g; //habe ich eingefügt
int b; //habe ich eingefügt
// Chose 2 pins for output; can be any valid output pins:
int dataPin  = 1;
int clockPin = 0;

// First parameter is the number of LEDs in the strand.  The LED strips
// are 32 LEDs per meter but you can extend or cut the strip.  Next two
// parameters are SPI data and clock pins:
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);


void setup() {
  
}

void loop() {

  

 if (nr <19){
  strip.setPixelColor(nr, r, g, b);
  strip.show();
}
 if (nr == 21){
  strip.setPixelColor(1, r, g, b);
  strip.setPixelColor(5, r, g, b);
  strip.setPixelColor(9, r, g, b);
        strip.show();
  // Start up the LED strip
  strip.begin();

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

  
        strip.setPixelColor(21, 0,   127,   0); //LED blau
        strip.show(); //Update LEDs to show the color
  delay(500);

}

O weh, das wollte ich nicht :wink:
Die erwartete Reaktion war:

Willst du eine Funktion mySetPixel( ...) definieren ?

Ja, das ist es vermutlich, was Stefan mir vorgeschlagen hat.

  • Dann hast du in der leeren 2. Reihe ein { vergessen
  • Das geht nur ausserhalb von setup()

Also sowas, noch vor void setup () { ... }:

void mySetPixel(byte nr, byte r, byte g, byte b)
{  
   if (nr <19) {
     strip.setPixelColor(nr, r, g, b);
     strip.show();
   }

   if (nr == 21) {
     strip.setPixelColor(1, r, g, b);
     strip.setPixelColor(5, r, g, b);
     strip.setPixelColor(9, r, g, b);
     strip.show();
   }

}

const byte dataPin=2;
const byte clockPin=3;

LPD8806 strip = LPD8806(18, dataPin, clockPin); // 

void setup() 
{
   strip.begin()
}

void loop ()
{
  // Beispiel für die Verwendung von mysetPixel()
   mySetPixel(1,127,127,0);  // einzelne LED : 1: gelb
   delay (1000);
   mySetPixel(19,80,0,0);  // Gruppe #19 = 1/5/9  rot (dunkel)
   delay (1000);
   mySetPixel(1,0,0,0);  // einzelne LED : 1: aus
   delay (1000);
   mySetPixel(19,0,0,0);  // Gruppe #19 = 1/5/9  aus
   delay (1000);
}

P.S. Es natürlich geht auch, ohne eine eigene Funktion zu definieren.
Was ist denn der Fehler in deinem letzten sketch ?

Super, danke, danke, danke...
Jetzt kann ich schlafen gehen.
Nochmal danke für eure Mühe!!!

Detlef

Zur Vollständigkeit nochmal hier der Sketch der bei mir nun funktioniert:

#include "LPD8806.h"
//#include "SPI.h"

// Example to control LPD8806-based RGB LED Modules in a strip

/*****************************************************************************/
int nLEDs = 18;
// Chose 2 pins for output; can be any valid output pins:
int dataPin  = 1;
int clockPin = 0;

// First parameter is the number of LEDs in the strand.  The LED strips
// are 32 LEDs per meter but you can extend or cut the strip.  Next two
// parameters are SPI data and clock pins:
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);
void mySetPixel(byte nr, byte r, byte g, byte b)
{  
   if (nr <19) {
     strip.setPixelColor(nr, r, g, b);
     strip.show();
   }

   if (nr == 21) {
     strip.setPixelColor(1, r, g, b);
     strip.setPixelColor(5, r, g, b);
     strip.setPixelColor(9, r, g, b);
     strip.show();
   }
if (nr == 22) {
     strip.setPixelColor(0, r, g, b);
     strip.setPixelColor(2, r, g, b);
     strip.setPixelColor(4, r, g, b);
     strip.setPixelColor(6, r, g, b);
     strip.setPixelColor(8, r, g, b);
     strip.setPixelColor(10, r, g, b);
     strip.setPixelColor(12, r, g, b);
     strip.setPixelColor(14, r, g, b);
     strip.setPixelColor(16, r, g, b);
     strip.show();
   }
   if (nr == 23) {
     strip.setPixelColor(1, r, g, b);
     strip.setPixelColor(3, r, g, b);
     strip.setPixelColor(5, r, g, b);
     strip.setPixelColor(7, r, g, b);
     strip.setPixelColor(9, r, g, b);
     strip.setPixelColor(11, r, g, b);
     strip.setPixelColor(13, r, g, b);
     strip.setPixelColor(15, r, g, b);
     strip.setPixelColor(17, r, g, b);
     strip.show();
   }
   // 24 sind alle
    if (nr == 24) {
     strip.setPixelColor(1, r, g, b);
     strip.setPixelColor(3, r, g, b);
     strip.setPixelColor(5, r, g, b);
     strip.setPixelColor(7, r, g, b);
     strip.setPixelColor(9, r, g, b);
     strip.setPixelColor(11, r, g, b);
     strip.setPixelColor(13, r, g, b);
     strip.setPixelColor(15, r, g, b);
     strip.setPixelColor(17, r, g, b);
     strip.setPixelColor(0, r, g, b);
     strip.setPixelColor(2, r, g, b);
     strip.setPixelColor(4, r, g, b);
     strip.setPixelColor(6, r, g, b);
     strip.setPixelColor(8, r, g, b);
     strip.setPixelColor(10, r, g, b);
     strip.setPixelColor(12, r, g, b);
     strip.setPixelColor(14, r, g, b);
     strip.setPixelColor(16, r, g, b);
     strip.show();
   }
}



void setup() 
{
   strip.begin();
}

void loop ()
{
  // Beispiel für die Verwendung von mysetPixel()
    mySetPixel(24,127,0,0);  // Gruppe #24 = alle  rot
    delay (5000);
    mySetPixel(24,0,0,0);  // Gruppe #24 = alle aus
   mySetPixel(24,0,127,0);  // Gruppe #24 = alle  blau
    delay (5000);
    mySetPixel(24,0,0,0);  // Gruppe #24 = alle aus
     mySetPixel(24,0,0,127);  // Gruppe #24 = alle  grün
   delay (5000);
   mySetPixel(24,0,0,0);  // Gruppe #24 = alle aus
  mySetPixel(22,127,0,0);  // Gruppe #22 = 0-16  rot
    mySetPixel(23,0,127,0);  // Gruppe #23 = 1-17  blau
   delay (5000);
 /*  mySetPixel(22,0,127,0);  // Gruppe #22 = 1-11  rot
   delay (5000);
   mySetPixel(22,0,0,127);  // Gruppe #22 = 1-11  rot
   delay (5000);
   mySetPixel(1,127,127,0);  // einzelne LED : 1: gelb
   delay (1000);
   mySetPixel(21,80,0,0);  // Gruppe #21 = 1/5/9  rot (dunkel)
   delay (1000);
   mySetPixel(1,0,0,0);  // einzelne LED : 1: aus
   delay (1000); */
   mySetPixel(24,0,0,0);  // Gruppe #24 = alle aus
   delay (5000);
}