Software für LED Animationen

Derzeitiger Stand, ich habe die Variablen etwas geändert:

// ******************** Definitionen für LED Animation ******************************************************

#ifdef LED_SR

// Declare NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LedPin, NEO_GRB + NEO_KHZ800);

// Zählvarbiablen
uint16_t loopCount;                             // Runterzählen der Loops
uint8_t animCount;                              // Wie oft die einmalige Animation ausgeführt wird bevor es zurück in die Hauptschleife (Animationsmodus 0) geht
uint8_t i;

// Datenvariablen
uint8_t currentDetectedVolume;                  // Speichern der aktuellen Lautstärke für späteren Vergleich
uint8_t lastDetectedVolume;                     // Speichern der Lautstärke um die Animation nur ein mal zu triggern
uint8_t volumeScope;                            // Differenz der von euch eingestellten minimalen und maximalen Lautstärke
uint8_t volumeScopeAmount;                      // Lautstärkenwert in deinem Scope
uint8_t volumeScopeAmountMod;

uint32_t  firstPixelHue = 0;
uint32_t  pixelHue;

uint32_t  TrckChgColor_FFW = 21845L;            // Farbe wird bei Animation nächstes Lied verwendet
uint32_t  TrckChgColor_REW = 43690L;            // Farbe wird bei Animation Lied zurück verwendet
uint8_t   TrckChgSpeed = 64;                    // Geschwindigkeit Animation Lied vor/zurück (1 bis 255)
uint8_t   TrckChgMaxBrightness = 255;           // Helligkeit Animation Lied vor/zurück (1 bis 255)
uint32_t  TrckChgProgress = 0;

uint8_t lsrAnimationMode;                       // Animationsmodus - 0: Daueranimation, 1-2 einmalige Animation (als Unterbrechung zu 0)
uint8_t lsrAnimationTrackMode;                  // Bei Animationsmodus Liedwechsel bestimmung der Farbe und Richtung
uint8_t currentDetectedTrack;                   // Speichern des aktuellen Tracks für späteren Vergleich
uint8_t lastDetectedTrack;                      // Speichern des Tracks um die Animation nur ein mal zu triggern

#ifdef LED_SR_Switch
bool lsrSwitch = false;                         // Ein-Ausschalten aktiviert, true wenn up und down Button long press
bool lsrEnable = true;                          // LED-Animation-Freigabe
bool lsrAudioBreak = false;                     // Wiedergabe gestoppt während Ein-Ausschalten LED-Animation .
bool lsrOffByStdby = false;                     // Ausschaltsignal LED-Animation durch Standbytimer Software only
#endif
#endif

Und die Animationen eigentlich komplett umgeschrieben:

//*************LED-Animaion inspired by @tON and @Thomas-Lehnert **************************
///////////////// Prüfung der einmaligen Animationen /////////////////

// ----------   Liedänderung erkennen und Animation aktivieren   ---------- //
currentDetectedTrack = currentQueueIndex;
if (currentDetectedTrack != lastDetectedTrack)
{
  strip.clear();   // über schwarz oder über die vorherige Animation, dann ausskommentieren
  if (currentQueueIndex > lastDetectedTrack) //nächstes Lied
  {
    lsrAnimationTrackMode = 1;
  }
  if (currentQueueIndex < lastDetectedTrack) // Lied zurück
  {
    lsrAnimationTrackMode = 2;
  }
  lsrAnimationMode = 1;
}

// ----------    Lautstärkenanpassung erkennen und Animation aktivieren    ---------- //
currentDetectedVolume = volume;
if (currentDetectedVolume != lastDetectedVolume)
{
  lsrAnimationMode = 2;
  animCount = strip.numPixels();
}

///////////////// Dauerhafte Loop Animationen /////////////////

// ----------   Loop Animation: Default Mode   ---------- //
if (lsrAnimationMode == 0 && loopCount == 0 && isPlaying() == false && knownCard == false)
{
    for(int i=(strip.numPixels()/2)-1; i>=0; i--) {
      pixelHue = firstPixelHue - (i * 65536L / (strip.numPixels()));
      strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
      strip.setPixelColor(strip.numPixels()-i-1, strip.gamma32(strip.ColorHSV(pixelHue)));
    }
    strip.show(); // Update strip with new contents
    
    firstPixelHue += 128;         // Geschwindigkeit der Animation, je kleiner um so langsamer
}

// ----------   Loop Animation: Musik spielt   ---------- //
if (lsrAnimationMode == 0 && loopCount == 0 && isPlaying() == true && knownCard == true)
{
    for(int i=0; i<strip.numPixels(); i++) {
      pixelHue = firstPixelHue + (i * 65536L / (strip.numPixels()*1));
      strip.setPixelColor(strip.numPixels()-1-i, strip.gamma32(strip.ColorHSV(pixelHue)));
    }
    strip.show(); // Update strip with new contents
    
    firstPixelHue += 384;       // Geschwindigkeit der Animation, je kleiner um so langsamer
 }

// ----------   Loop Animation: Musik pausiert   ---------- //
if (lsrAnimationMode == 0 && loopCount == 0 && isPlaying() == false && knownCard == true)
{
    for(int i=0; i<strip.numPixels(); i++) {
      pixelHue = firstPixelHue + (i * 65536L / (strip.numPixels()*1));
      strip.setPixelColor(strip.numPixels()-1-i, strip.ColorHSV(pixelHue, 192, 12));       
    }
    //strip.setBrightness(64);
    strip.show(); // Update strip with new contents
    
    firstPixelHue += 16;         // Geschwindigkeit der Animation, je kleiner um so langsamer
}
  
///////////////// Einmalige Animationen bei einem Ereignis /////////////////

// ----------   Einmalige Animation: Liedänderung    ---------- //
if (lsrAnimationMode == 1 && loopCount == 0)
{
  animCount = strip.numPixels();
  uint32_t  Balken = TrckChgProgress;
  i = 0;
  
  while (Balken > TrckChgMaxBrightness)
    {
       if (lsrAnimationTrackMode == 1){
            strip.setPixelColor(strip.numPixels()-i-1, strip.ColorHSV(TrckChgColor_FFW, 255, TrckChgMaxBrightness)); 
       }else{
            strip.setPixelColor(i, strip.ColorHSV(TrckChgColor_REW, 255, TrckChgMaxBrightness));             
       }
       Balken -= TrckChgMaxBrightness;
       i++;
       if (animCount != 0)
          {
            animCount--;
          }
    }
  
  if ( animCount != 0 && Balken > 0 )
    {
       if (lsrAnimationTrackMode == 1){
            strip.setPixelColor(strip.numPixels()-i-1, strip.ColorHSV(TrckChgColor_FFW, 255, Balken)); 
       }else{
            strip.setPixelColor(i, strip.ColorHSV(TrckChgColor_REW, 255, Balken));             
       }
    }
  
  strip.show();
  
  TrckChgProgress += TrckChgSpeed;
  
  if (animCount == 0)
  {
    lsrAnimationMode = 0;
    TrckChgProgress = 0;
    loopCount = 40;
  }
}

// ----------   Einmalige Animation: Prozentuale Lautstärkenanpassung   ---------- //
if (lsrAnimationMode == 2 && loopCount == 0)
{
  if (animCount != 0)
  {
     animCount--;
  }

  if (currentDetectedVolume != lastDetectedVolume)
  {
     animCount = 50; 
  }
  
  volumeScope = (mySettings.maxVolume - mySettings.minVolume);
  volumeScopeAmount = (volume - mySettings.minVolume) * (LED_COUNT - 1) / volumeScope; // Lautstärkenanzeige angepasst an die Anzahl der LEDs
  volumeScopeAmountMod = (volume - mySettings.minVolume) * (LED_COUNT - 1) % volumeScope;

#ifdef EarPhone
 if (SpkisOn == false)
  { 
  volumeScope = (mySettings.maxEarVol - mySettings.minEarVol);
  volumeScopeAmount = (volume - mySettings.minEarVol) * (LED_COUNT - 1) / volumeScope; // Lautstärkenanzeige Kopfhörer angepasst an die Anzahl der LEDs
  volumeScopeAmountMod = (volume - mySettings.minEarVol) * (LED_COUNT - 1) % volumeScope; 
  }
#endif

  uint8_t VolMaxBrightness = 255;
  
  uint16_t VolColor = 23000L - (((volume - mySettings.minVolume) * 23000L) / volumeScope);
  for (i = 0; i < strip.numPixels(); i++)
    {
      if (i<=volumeScopeAmount){
            strip.setPixelColor(strip.numPixels()-i-1, strip.ColorHSV(VolColor, 255, VolMaxBrightness)); 
        }
      else if (i==volumeScopeAmount+1){
            strip.setPixelColor(strip.numPixels()-i-1, strip.ColorHSV(VolColor, 255, ((volumeScopeAmountMod * VolMaxBrightness) / volumeScope))); 
        }
      else{
            strip.setPixelColor(strip.numPixels()-i-1, strip.ColorHSV(VolColor, 255, 0)); 
        }
    }

  strip.show();
  

  if (animCount == 0)
  {
    lsrAnimationMode = 0;
    TrckChgProgress = 0;        
  }
}

// ----------   Countdown Zähler über den loop als Ersatz zur delay Funktion   ----------
if (loopCount != 0 ) {
  loopCount--;
}

// ----------   Dadurch wird die Änderung der Lautstärke bzw. Track nur ein mal registiert   ----------
lastDetectedVolume = currentDetectedVolume;
lastDetectedTrack = currentDetectedTrack;

#ifdef LED_SR_Switch
  }
#endif

  if (lsrAudioBreak == true)    // wenn Wiedergabe von LED On/Off gestoppt
  {
mp3.start();                 // Wiedergabe fortsetzen
disablestandbyTimer();
lsrAudioBreak = false;       // Marker Wiedergabe läuft wieder
  }
}
#endif                           // Ende Abfrage Aktivierung LED Animation (#ifdef LED_SR)

// *************************** Ende LED Animation ******************************************

Vielleicht nutzt es ja auch anderen.

3 „Gefällt mir“