Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

  1. #if GARLAND_SUPPORT
  2. #include "../anim.h"
  3. #include "../palette.h"
  4. //------------------------------------------------------------------------------
  5. class AnimWaves : public Anim {
  6. private:
  7. int bra_phase;
  8. int bra_phase_speed;
  9. byte bra_speed;
  10. byte bra_min;
  11. int sign;
  12. public:
  13. AnimWaves() : Anim("Waves") {
  14. }
  15. void SetupImpl() override {
  16. curColor = palette->getRndInterpColor().max_bright();
  17. glowSetUp();
  18. sign = braPhaseSpd > 128 ? -1 : 1;
  19. bra_phase = secureRandom(255);
  20. bra_phase_speed = secureRandom(2, 5);
  21. bra_speed = secureRandom(4, 12);
  22. bra_min = secureRandom(20, 30);
  23. }
  24. void Run() override {
  25. int bra = bra_phase;
  26. int8_t bra_inc = -sign * bra_speed;
  27. for (int i = 0; i < numLeds; ++i) {
  28. leds[i] = curColor;
  29. glowForEachLed(i);
  30. leds[i] = leds[i].brightness((byte)bra);
  31. bra += bra_inc;
  32. if (bra > 255 || bra < bra_min) {
  33. bra_inc = -bra_inc;
  34. bra = bra > 255 ? 255 : bra_min;
  35. }
  36. }
  37. glowRun();
  38. bra_phase += bra_phase_speed;
  39. if (bra_phase > 255 || bra_phase < bra_min) {
  40. bra_phase_speed = -bra_phase_speed;
  41. sign = -sign;
  42. bra_phase = bra_phase > 255 ? 255 : bra_min;
  43. }
  44. }
  45. };
  46. #endif // GARLAND_SUPPORT