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.

53 lines
1.4 KiB

  1. #if GARLAND_SUPPORT
  2. #include "../anim.h"
  3. #include "../color.h"
  4. #include "../palette.h"
  5. //seq keeps phases: 0..127 increasing, 128..255 decreasing, ends at 255 (steady off)
  6. //ledstmp keeps color of stars
  7. //------------------------------------------------------------------------------
  8. class AnimStars : public Anim {
  9. public:
  10. AnimStars() : Anim("Stars") {
  11. }
  12. void SetupImpl() override {
  13. //inc is (average) interval between appearance of new stars
  14. inc = secureRandom(2, 5);
  15. //reset all phases
  16. for (int i = 0; i < numLeds; ++i)
  17. seq[i] = 255;
  18. }
  19. void Run() override {
  20. for (byte i = 0; i < numLeds; i++) {
  21. byte phi = seq[i];
  22. if (phi < 254) {
  23. Color col = ledstmp[i];
  24. if (phi <= 127) {
  25. leds[i] = col.brightness(phi << 1);
  26. } else {
  27. leds[i] = col.brightness((255 - phi) << 1);
  28. }
  29. seq[i] += 2;
  30. } else {
  31. leds[i].r = 0;
  32. leds[i].g = 0;
  33. leds[i].b = 0;
  34. }
  35. }
  36. if (secureRandom(inc) == 0) {
  37. byte pos = secureRandom(numLeds);
  38. if (seq[pos] > 250) {
  39. seq[pos] = 0;
  40. ledstmp[pos] = palette->getRndInterpColor();
  41. }
  42. }
  43. }
  44. };
  45. #endif // GARLAND_SUPPORT