sticilface / Melvanimate

Melvanimate
60 stars 7 forks source link

Additional Lighting effects Feature request #15

Closed jpfy closed 8 years ago

jpfy commented 8 years ago

If would be great if there was a way to add additional effects. In particular a fire effect. I presume it means creating a effect c++ and helper file but I am not sure how to go about this.

sticilface commented 8 years ago

This is totally possible and very easy! just follow the example for simplecolor and off...

  1. register the effect name and function in setup.
  lights.Add("Your effect name",  new SimpleEffect(YourEffectFunctionFn));       

then create the function for the effect. you have access to the ptr for effect handler which you can cast to simple effect as shown below. this give you access to effect.color() and effect.brightness().
place code you want run once as the effect is started in PRE_EFFECT, the looped effect code in RUN_EFFECT and after your effect POST_EFFECT. There are some methods to hold of moving to the next stage, or effect if there are active animations. see lights.autoWait(); in the simplecolourfn in the example. effect.SetTimeout(2000); controls the speed of the loop function, if you want to slow is down.

void YourEffectFunctionFn(effectState &state, EffectHandler* ptr)
{

  if (ptr) {

    SimpleEffect& effect = *static_cast<SimpleEffect*>(ptr);

    switch (state) {
   case PRE_EFFECT: {

      break;
    }

    case RUN_EFFECT: {

      break;
    }
    case POST_EFFECT: {

      break;
    }

    case EFFECT_REFRESH: {
      state = PRE_EFFECT;
      break;
    }
    }
  }
}

hope that helps. All this can go in the main ino file, so no need to create cpp files