LED Code

hallo ich wollte mal wissen ob man diesen code auch an 2 pins betreiben kann ? ich hatte es schon versucht aber leider immer wieder ohne erfolg ! hier ist dann mal der

#include <Adafruit_NeoPixel.h>

#define PIN 8
#define Pixels 120
#define BG 1

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixels, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.

int color;
int center = 0;
int step = -1;
int maxSteps = 16;
float fadeRate = 0.6;
int diff;

//background color
uint32_t currentBg = random(256);
uint32_t nextBg = currentBg;

void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}

void loop () {
ripple();
}

void ripple() {
if (BG){
if (currentBg == nextBg) {
nextBg = random(256);
}
else if (nextBg > currentBg) {
currentBg++;
} else {
currentBg--;
}
for(uint16_t l = 0; l < Pixels; l++) {
strip.setPixelColor(l, Wheel(currentBg, 0.1));
}
} else {
for(uint16_t l = 0; l < Pixels; l++) {
strip.setPixelColor(l, 0, 0, 0);
}
}

if (step == -1) {
center = random(Pixels);
color = random(256);
step = 0;
}

if (step == 0) {
strip.setPixelColor(center, Wheel(color, 1));
step ++;
}
else {
if (step < maxSteps) {
strip.setPixelColor(wrap(center + step), Wheel(color, pow(fadeRate, step)));
strip.setPixelColor(wrap(center - step), Wheel(color, pow(fadeRate, step)));
if (step > 3) {
strip.setPixelColor(wrap(center + step - 3), Wheel(color, pow(fadeRate, step - 2)));
strip.setPixelColor(wrap(center - step + 3), Wheel(color, pow(fadeRate, step - 2)));
}
step ++;
}
else {
step = -1;
}
}

strip.show();
delay(50);
}

int wrap(int step) {
if(step < 0) return Pixels + step;
if(step > Pixels - 1) return step - Pixels;
return step;
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos, float opacity) {

if(WheelPos < 85) {
return strip.Color((WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity, 0);
}
else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color((255 - WheelPos * 3) * opacity, 0, (WheelPos * 3) * opacity);
}
else {
WheelPos -= 170;
return strip.Color(0, (WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity);
}
}

Ob es die Adafruit Neopixel Lib kann, weiß ich nicht. Die FastLed kann es auf jedenfall.

Interessanter wäre es, wie du es versucht hast, 2 Strips anzuschließen. Sollte eigentlich ganz einfach gehen.

#include <Adafruit_NeoPixel.h>
 
#define PIN1 8
#define PIN2 9

#define PIXEL1 120
#define PIXEL2 10
 
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(PIXEL1, PIN1, NEO_GRB + NEO_KHZ800); // ?? Sicher dass es NEO_GRB + NEO_KHZ800 heißt?
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(PIXEL2, PIN2, NEO_GRB + NEO_KHZ800);

void setup() {
  strip1.begin();
  strip1.show(); // Initialize all pixels to 'off'

  strip2.begin();
  strip2.show(); // Initialize all pixels to 'off'

}

Das hingegen ist schlecht gelöst. BG wird nach dem Kompilieren NIE 0! Somit wird else nie ausgeführt, belegt aber Platz auf dem MCU.

#define BG 1

void ripple() {
  if (BG){
    if (currentBg == nextBg) {
      nextBg = random(256);
    } 
    else if (nextBg > currentBg) {
      currentBg++;
    } else {
      currentBg--;
    }
    for(uint16_t l = 0; l < Pixels; l++) {
      strip.setPixelColor(l, Wheel(currentBg, 0.1));
    }
  } else {
    for(uint16_t l = 0; l < Pixels; l++) {
      strip.setPixelColor(l, 0, 0, 0);
    }
  }

Besser

#define BG // was auch immer es sein soll

void func() {
#ifdef BG
// do
#else
// else
#endif
}