Hallo Leudeee,
hab mal im Internet ne echt coole Neopixel Funktion gefunden, genannt Meteor
void Meteor( byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
for (int i = 0; i < Anzahl_Pixel + Anzahl_Pixel; i++) {
// fade brightness all LEDs one step
for (int j = 0; j < Anzahl_Pixel; j++) {
if ( (!meteorRandomDecay) || (random(10) > 5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
// draw meteor
for (int j = 0; j < meteorSize; j++) {
if ( ( i - j < Anzahl_Pixel) && (i - j >= 0) ) {
strip.setPixelColor(i - j, 255, 0, 0);
}
}
strip.show();
delay(SpeedDelay);
}
}
void fadeToBlack(int ledNo, byte fadeValue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
uint32_t oldColor;
uint8_t r, g, b;
int value;
oldColor = strip.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);
r = (r <= 10) ? 0 : (int) r - (r * fadeValue / 256);
g = (g <= 10) ? 0 : (int) g - (g * fadeValue / 256);
b = (b <= 10) ? 0 : (int) b - (b * fadeValue / 256);
strip.setPixelColor(ledNo, r, g, b);
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[ledNo].fadeToBlackBy( fadeValue );
#endif
}
Hab die mal auf meinen Code zugeschnitten und finde die mega schön.
Nur gibts ein Problem, die läuft über Delay und das ist ein killer für mich, da ich neben dieser Funktion weitere Sachen im Hintergrund ausführen muss. Daher muss Millis() rein…
Hab schon vieles Ausprobiert, doch alles verändert die schöne Funktion…
Mein aktueller Code ist das hier… das kommt am nächsten an die Ursprüngliche Funktion ran, jedoch Blitzt das so komisch jeden Durchgang.
Kann mir jemand Tipps geben dazu ?
void Meteor(byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
unsigned long currentMillisMeteor = millis();
static unsigned long previousMillisMeteor = 0;
static byte j = 0;
if ((currentMillisMeteor - previousMillisMeteor) >= 200) {
previousMillisMeteor = currentMillisMeteor;
for (int i = 0; i < Anzahl_Pixel + Anzahl_Pixel; i++) {
// fade brightness all LEDs one step
for (int j = 0; j < Anzahl_Pixel; j++) {
if ( (!meteorRandomDecay) || (random(10) > 5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
// draw meteor
for (int j = 0; j < meteorSize; j++) {
if ( ( i - j < Anzahl_Pixel) && (i - j >= 0) ) {
strip.setPixelColor(i - j, R, G, B);
}
}
strip.show();
j++;
//delay(SpeedDelay);
}
}
}
Danke im Voraus
Gruß Franz