These are chat archives for Makuna/NeoPixelBus

12th
Nov 2016
protolyser
@protolyser
Nov 12 2016 00:20
when do you think you have the new filter stuff finished?
Michael Miller
@Makuna
Nov 12 2016 06:17
Its usually done when its done ;-) But I would not expect before December.
protolyser
@protolyser
Nov 12 2016 06:48
December this year or in ten years? ;) waiting for it :)
protolyser
@protolyser
Nov 12 2016 19:16

what is the best way to setup different animations and switching them? I'm controlling my ESP12-e via MQTT. I have a modeChanger() function running in loop that switches different functions:

void modeChanger(){
  switch (currentMode)
  {
      case 1:
       turnOff(); 
        strip.SetPixelColor(topo.Map(left, top), white);
        strip.SetPixelColor(topo.Map(right, top), red);
        strip.SetPixelColor(topo.Map(right, bottom), green);
        strip.SetPixelColor(topo.Map(left, bottom), blue);
        strip.SetPixelColor(topo.Map(centerx, centery), red);
        strip.Show();
        delay(200);
      break;
      case 2:
        randomColor();
        SetupAnimationSet();
        animations.UpdateAnimations();
            strip.Show();
      break;
      case 4:
        SetupAnimationSetCyclon();
        animations.UpdateAnimations();
            strip.Show();
      break;
    default:
      break;
  }
}

Now I want to call some animations from the examples for example the cyclon and other stuff. Problem is: how do I handle the setup of the functions? to call that from within the loop.

Michael Miller
@Makuna
Nov 12 2016 20:42
I don't see the code that sets up the animations here; so I am unsure what you are trying to do to suggest a better way.
In general, think of each animation (index) as something you want to run. You can start and stop each one. The param includes state if you want to trigger another when one stops.
protolyser
@protolyser
Nov 12 2016 20:46
void SetupAnimationSet()
{
    // setup some animations
    for (uint16_t pixel = 0; pixel < PixelCount; pixel++)
    {
        const uint8_t peak = 128;

        // pick a random duration of the animation for this pixel
        // since values are centiseconds, the range is 1 - 4 seconds
        uint16_t time = random(100, 400);

        // each animation starts with the color that was present
        RgbColor originalColor = strip.GetPixelColor(pixel);
        // and ends with a random color
        RgbColor targetColor = RgbColor(random(peak), random(peak), random(peak));
        // with the random ease function
        AnimEaseFunction easing;
        switch (random(3))
        {
        case 0:
            easing = NeoEase::CubicIn;
            break;
        case 1:
            easing = NeoEase::CubicOut;
            break;
        case 2:
            easing = NeoEase::QuadraticInOut;
            break;
        }
    }
}

This is for example the one out of your examples. It works calling that with my switch case and mqtt. But now I want to use the "cyclon" and there you start the animation in "setup".
and the random color thing here:

void randomColor()
{
    // just pick some colors
    for (uint16_t pixel = 0; pixel < PixelCount; pixel++)
    {
        RgbColor color = RgbColor(random(255), random(255), random(255));
        strip.SetPixelColor(pixel, color);
    }

}

protolyser
@protolyser
Nov 12 2016 20:52
in the NeoPixelAnimation.ino example you just call "animations.UpdateAnimations();" in loop. in cyclon there is the animations.StartAnimation(0, 5, FadeAnimUpdate); setup. Can I use startanimation in loop? or how does it work?
what I basically want to do is for exmple:
MQTT --> Mode 1 --> NeoPixelMatrix Shows random colors
MQTT --> Mode 2 --> NeoPixelMatrix does cyclon
MQTT --> Mode 3 --> Call predefined pixels individually
MQTT --> Mode 4 --> Some other animation
What I don't understand is how I can seperate all animations differently without mixing all up.
How I currently try to do it (defining everything distributed everywhere) can't be right because that gets really messy with every new animation added.