Lichteffekte einer LED Strips (WS2811) mit dem Arduino wechseln

Das blockiert, weshalb man die Taste gedrückt halten muß, bis das letzte Pixel leuchtet.

Ich Wenn der Arduino und der Stripe gleichzeitig aus der selben Quelle gespeist wird und der Taster am GND angelötet ist, sollte das gehen.
Aber: Kann es sein, das Du den UNO mit USB betreibst und die 12V extern einspeist? Dann fehlt Dir die Verbindung zwischen GND Stripe und GND UNO. Die muss noch dazu. Sonst leuchtet das auch nicht.

Ach, da ist noch ne Falle drin... Ich hab die blos aufgeteilt ohne hinzusehen. :innocent:

Fallenlöser:

void ledWhiteBlack()
{
  static int whiteLed = 0;
  EVERY_N_MILLISECONDS( 100 )
  {
    leds[whiteLed] = CRGB::White;
    FastLED.show();
    leds[whiteLed] = CRGB::Black;
    whiteLed++;
    if (whiteLed >= NUM_LEDS) whiteLed = 0;
  }
}

Das war auch der fall, hab alles aus dem 12V Netzteil gezogen, es hat weiß geblinkt sonst nichts, trotz drücken, aber zu dem Zeitpunkt wusste ich noch nicht das ich es gedrückt halten muss.

Und ich kann den Arduino schlecht per USB betreiben und zeitgleich an 12V Netzteil ich glaube das würde der Arduino nicht so geil finden

PERFEKT, hab den Sketch jetzt korrigiert aus Post #24 Taster läuft wie am Schnürchen....er reagiert zumindest ich kann von dem weißem geblinkte zum Regenbogen Effekt umschalten und diesen Effekt sogar pausieren...

#include <FastLED.h>

#define NUM_LEDS 68  // How many leds are in the strip?
#define DATA_PIN 6

CRGB leds[NUM_LEDS];  // This is an array of leds.  One item for each led in your strip.

uint8_t gHue = 0; // rotating "base color" used by many of the patterns

const byte tasterPin = 2;
const unsigned long bounceTime = 40;

byte auswahl = 0;
const byte maxFunktion = 3;

void setup()
{
  Serial.begin(115200);
  Serial.println(F("Start..."));
  pinMode (tasterPin, INPUT_PULLUP);
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
  leds[0] = CRGB::Red;
  leds[1] = CRGB::Green;
  leds[2] = CRGB::Blue;
  FastLED.show();
  delay(3000);
}

void loop()
{
  funktionAuswahl();
}

void funktionAuswahl()
{
  static unsigned long pressTimer = 0;
  static bool lastPressed = false;
  if (!digitalRead(tasterPin))
  {
    if (!lastPressed)
    {
      auswahl++;
      Serial.println(F("Taste gedrückt"));
      if (auswahl >= maxFunktion)
      {
        auswahl = 0;
      }
      pressTimer = millis();
      lastPressed = true;
    }
  }
  else if (millis() - pressTimer > bounceTime)
  {
    lastPressed = false;
  }
  switch (auswahl)
  {
    case 0: ledWhiteBlack(); break;
    case 1: rainbow(); break;
    case 2: Serial.println(F("Denkste!")); break;
  }
}

void ledWhiteBlack()
{
  static int whiteLed = 0;
  EVERY_N_MILLISECONDS( 100 )
  {
    leds[whiteLed] = CRGB::White;
    FastLED.show();
    leds[whiteLed] = CRGB::Black;
    whiteLed++;
    if (whiteLed >= NUM_LEDS) whiteLed = 0;
  }
}
void rainbow()
{
  fill_rainbow( leds, NUM_LEDS, gHue, 7);
  FastLED.show();
  EVERY_N_MILLISECONDS( 20 )
  {
    gHue++;  // slowly cycle the "base color" through the rainbow
  }
}

Ach doch, das geht schon.
Aber wie @agmue schrieb: tausch mal die Funktion aus.
Ich zumindest kann hier den Tastendruck nachstellen und bekomm auch die Ausgabe aus dem Sketch.

Diesmal war ich zu spät :crazy_face:

Läuft aufm Seriellen Monitor sowie auf den LED Strips wie am Schnürchen... :slight_smile:

Ich will mich damit schonmal Herzlich bedanken, jetzt bin ich wieder einen Schritt weiter und kann auf diesen Sketch aufbauen.

LG Migel

In den Beispielen der Bibliothek wirst Du Anregungen für Animationen finden.

meinst du das hier ?


wenn ja wäre das Fantastisch damit hätte ich 22 Effekte
Ich hab den Ordner in der Zip nicht gefunden, da ich die Zip nur zum Importieren genutzt habe...:slight_smile:

Nö, nicht peinlich. So etwas passiert jedem.
Man kennt dann nach dem 1. Mal das Problem und kann es korrigieren.

Gruß Tommy

Ja :slightly_smiling_face:

In FirstLight.ino habe ich mich mit dem weißen Punkt bedient.

Nee, es werden verschiedene Aspekte behandelt und DemoReel100.ino enthält schon die Effekte SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm }; zum automatischen Umschalten und rainbow() solltest Du wiedererkennen.

Hier sind auch noch Effekte zu finden und auch erklärt. Hat mir gut geholfen.

Sorry wenn ich so oft nachfragen muss, bei einigen Effekten habe ich es geschafft sie in mein Sketsch mit einzubinden aber bei den letzten Effekt Fire2012() tut sich Bein Drücken des Tasters nichts, stattdessen wird wieder der Erste Effekt abgespielt, ich weiß nicht was ich da falsch gemacht habe.

Sorry wenn ich so oft nachfrage, C++ ist Neuland für mich :wink:

Hier der Sketch: laut dem Programm ist der Fehlerfrei:

#include <FastLED.h>

#define NUM_LEDS 68  // How many leds are in the strip?
#define DATA_PIN 6
#define SPARKING 120
#define COOLING  55

bool gReverseDirection = false;

CRGB leds[NUM_LEDS];  // This is an array of leds.  One item for each led in your strip.

uint8_t gHue = 0; // rotating "base color" used by many of the patterns

const byte tasterPin = 2;
const unsigned long bounceTime = 40;

byte auswahl = 0;
const byte maxFunktion = 3;

void setup()
{
  pinMode (tasterPin, INPUT_PULLUP);
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
  leds[0] = CRGB::Red;
  leds[1] = CRGB::Green;
  leds[2] = CRGB::Blue;
  FastLED.show();
  delay(3000);
}

void loop()
{
  funktionAuswahl();
}

void funktionAuswahl()
{
  static unsigned long pressTimer = 0;
  static bool lastPressed = false;
  if (!digitalRead(tasterPin))
  {
    if (!lastPressed)
    {
      auswahl++;
      if (auswahl >= maxFunktion)
      {
        auswahl = 0;
      }
      pressTimer = millis();
      lastPressed = true;
    }
  }
  else if (millis() - pressTimer > bounceTime)
  {
    lastPressed = false;
  }
  switch (auswahl)
  {
    case 0: rainbow(); break;
    case 1: confetti(); break; 
    case 2: bpm(); break;
    case 3: Fire2012(); break;
  }
 }
void rainbow()
{
  fill_rainbow( leds, NUM_LEDS, gHue, 7);
  FastLED.show();
  EVERY_N_MILLISECONDS( 20 )
{
    gHue++;
  }

}
void confetti() 
{
  fadeToBlackBy( leds, NUM_LEDS, 10);
  FastLED.show();
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV( gHue + random8(64), 200, 255);
  }
  void bpm()
{
  uint8_t BeatsPerMinute = 62;
  CRGBPalette16 palette = PartyColors_p;
  FastLED.show();
  uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  }
}
void Fire2012()
{
// Array of temperature readings at each simulation cell
  static uint8_t heat[NUM_LEDS];

  // Step 1.  Cool down every cell a little
    for( int i = 0; i < NUM_LEDS; i++) {
      heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
    }
  
    // Step 2.  Heat from each cell drifts 'up' and diffuses a little
    for( int k= NUM_LEDS - 1; k >= 2; k--) {
      heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
    }
    
    // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
    if( random8() < SPARKING ) {
      int y = random8(7);
      heat[y] = qadd8( heat[y], random8(160,255) );
    }

    // Step 4.  Map from heat cells to LED colors
    for( int j = 0; j < NUM_LEDS; j++) {
      CRGB color = HeatColor( heat[j]);
      int pixelnumber;
      if( gReverseDirection ) {
        pixelnumber = (NUM_LEDS-1) - j;
      } else {
        pixelnumber = j;
      }
      leds[pixelnumber] = color;
    }
}

Müßtest Du das nicht erhöhen?

hab das gerade um eine Funktion erhöht auf 4, ohne Erfolg, der vorletzte Effekt wird nur pausiert und beim erneuten Drücken fängt es von vorne an :frowning:

Ich hab das mal mit einer Seriellen Ausgabe probiert.
Laut dem läuft es durch:

Sag mal kann es ein, das ein .show() fehlt?

#include <FastLED.h>

#define NUM_LEDS 68  // How many leds are in the strip?
#define DATA_PIN 6
#define SPARKING 120
#define COOLING  55

bool gReverseDirection = false;

CRGB leds[NUM_LEDS];  // This is an array of leds.  One item for each led in your strip.

uint8_t gHue = 0; // rotating "base color" used by many of the patterns

const byte tasterPin = 2;
const unsigned long bounceTime = 40;

byte auswahl = 0;
const byte maxFunktion = 4;

void setup()
{
  Serial.begin(115200);
  Serial.println(F("Start..."));
  pinMode (tasterPin, INPUT_PULLUP);
  FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
  leds[0] = CRGB::Red;
  leds[1] = CRGB::Green;
  leds[2] = CRGB::Blue;
  FastLED.show();
  delay(3000);
}

void loop()
{
  funktionAuswahl();
}

void funktionAuswahl()
{
  static unsigned long pressTimer = 0;
  static bool lastPressed = false;
  if (!digitalRead(tasterPin))
  {
    if (!lastPressed)
    {
      auswahl++;
      if (auswahl >= maxFunktion)
      {
        auswahl = 0;
      }
      pressTimer = millis();
      lastPressed = true;
    }
  }
  else if (millis() - pressTimer > bounceTime)
  {
    lastPressed = false;
  }
  switch (auswahl)
  {
    case 0: rainbow(); break;
    case 1: confetti(); break;
    case 2: bpm(); break;
    case 3: Fire2012(); break;
  }
}
void rainbow()
{
  fill_rainbow( leds, NUM_LEDS, gHue, 7);
  FastLED.show();
  EVERY_N_MILLISECONDS( 20 )
  {
    gHue++;
  }
}
void confetti()
{
  fadeToBlackBy( leds, NUM_LEDS, 10);
  FastLED.show();
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV( gHue + random8(64), 200, 255);
}
void bpm()
{
  uint8_t BeatsPerMinute = 62;
  CRGBPalette16 palette = PartyColors_p;
  FastLED.show();
  uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  for ( int i = 0; i < NUM_LEDS; i++)  //9948
  {
    leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
  }
}
void Fire2012()
{
  // Array of temperature readings at each simulation cell
  static uint8_t heat[NUM_LEDS];
  // Step 1.  Cool down every cell a little
  for ( int i = 0; i < NUM_LEDS; i++)
  {
    heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
    Serial.print(F("Step1: ")); Serial.println(i);
  }
  // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  for ( int k = NUM_LEDS - 1; k >= 2; k--)
  {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
    Serial.print(F("Step2: ")); Serial.println(k);
  }
  // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  if ( random8() < SPARKING )
  {
    int y = random8(7);
    heat[y] = qadd8( heat[y], random8(160, 255) );
    Serial.print(F("Step3: ")); Serial.println(y);
  }
  // Step 4.  Map from heat cells to LED colors
  for ( int j = 0; j < NUM_LEDS; j++)
  {
    Serial.print(F("Step4: ")); Serial.println(j);
    CRGB color = HeatColor( heat[j]);
    int pixelnumber;
    if ( gReverseDirection )
    {
      pixelnumber = (NUM_LEDS - 1) - j;
    }
    else
    {
      pixelnumber = j;
    }
    leds[pixelnumber] = color;
    Serial.print(F("Step4 pixel: ")); Serial.println(pixelnumber);
  }
}

Bei mir wird der Effekt Fire2012() einfach übersprungen

So dann Quasi ?

void Fire2012()
{
  // Array of temperature readings at each simulation cell
  static uint8_t heat[NUM_LEDS];
  FastLED.show();
  // Step 1.  Cool down every cell a little
  for ( int i = 0; i < NUM_LEDS; i++)
  {
    heat[i] = qsub8( heat[i],  random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
    Serial.print(F("Step1: ")); Serial.println(i);
  }
  // Step 2.  Heat from each cell drifts 'up' and diffuses a little
  for ( int k = NUM_LEDS - 1; k >= 2; k--)
  {
    heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
    Serial.print(F("Step2: ")); Serial.println(k);
  }
  // Step 3.  Randomly ignite new 'sparks' of heat near the bottom
  if ( random8() < SPARKING )
  {
    int y = random8(7);
    heat[y] = qadd8( heat[y], random8(160, 255) );
    Serial.print(F("Step3: ")); Serial.println(y);
  }
  // Step 4.  Map from heat cells to LED colors
  for ( int j = 0; j < NUM_LEDS; j++)
  {
    Serial.print(F("Step4: ")); Serial.println(j);
    CRGB color = HeatColor( heat[j]);
    int pixelnumber;
    if ( gReverseDirection )
    {
      pixelnumber = (NUM_LEDS - 1) - j;
    }
    else
    {
      pixelnumber = j;
    }
    leds[pixelnumber] = color;
    Serial.print(F("Step4 pixel: ")); Serial.println(pixelnumber);
  }
}