Guest User

animationGlam

a guest
Oct 16th, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. #include "FastLED.h"
  2.  
  3. #define NUM_LEDS 60
  4.  
  5. CRGB leds[NUM_LEDS];
  6.  
  7. void setup()
  8. {
  9. LEDS.addLeds<WS2811, 2, GRB>(leds, NUM_LEDS);
  10. //initialize glam with your preferences
  11. //animationGlam();
  12. }
  13.  
  14. void loop()
  15. {
  16. animationGlam();
  17. LEDS.show();
  18. }
  19.  
  20. int LEDalpha[NUM_LEDS];
  21. byte LEDaction[NUM_LEDS];
  22. int LEDtimer[NUM_LEDS];
  23. byte LEDhue[NUM_LEDS];
  24.  
  25. int timerMax = 100;
  26. byte variation = 0;
  27. byte variationBase = 0;
  28. byte sat = 255;
  29. byte val = 255;
  30. float appearShift = 0.002;
  31. float disappearShift = 0.005;
  32. int interruptEvery = 500;
  33.  
  34. void animationGlam(byte _variationBase,byte _variation,float _scatter,float _fadeIn,float _fadeOut)
  35. {
  36. variationBase = _variationBase;
  37. variation = _variation;
  38. timerMax = _scatter;
  39. appearShift = _fadeIn;
  40. disappearShift = _fadeOut;
  41. animation = 2;
  42. }
  43. void animationGlam()
  44. {
  45. for (byte iLed = 0; iLed < NUM_LEDS; iLed++)
  46. {
  47. switch (LEDaction[iLed])
  48. {//action
  49. case 0://nothing
  50. {
  51. if (LEDtimer[iLed] == -1)
  52. {
  53. if (LEDalpha[iLed] == 0)
  54. {
  55.  
  56. switch (random(2))
  57. {
  58. case 0://set timer
  59. LEDtimer[iLed] = random(timerMax);
  60. break;
  61. case 1://appear
  62. LEDaction[iLed] = 1;
  63. break;
  64. }
  65. }
  66. else if (LEDalpha[iLed] > 0)
  67. {
  68. switch (random(2))
  69. {
  70. case 0://set timer
  71. LEDtimer[iLed] = random(timerMax);
  72. break;
  73. case 1://disappear
  74. LEDaction[iLed] = 2;
  75. break;
  76. }
  77. }
  78. }
  79. else
  80. {//timer runter zählen
  81. if (LEDtimer[iLed] != -1)
  82. {
  83. LEDtimer[iLed]--;
  84. }
  85. }
  86. }
  87. break;
  88. case 1://appear
  89. {
  90. //Farbe durch zufall wählen
  91. if (LEDalpha[iLed] == 0)
  92. {
  93. LEDhue[iLed] = (byte)(variationBase + random(variation));
  94. }
  95.  
  96. LEDalpha[iLed] += appearShift * 10000;
  97. if (LEDalpha[iLed] >= 10000) //ist erschienen
  98. {
  99. LEDalpha[iLed] = 10000;
  100. LEDaction[iLed] = 0;
  101. LEDtimer[iLed] = -1;
  102. }
  103.  
  104. int a = 1;
  105. if (a == random(interruptEvery))//durch zufall abbrechen
  106. {
  107. LEDaction[iLed] = 0;
  108. LEDtimer[iLed] = -1;
  109. }
  110. }
  111. break;
  112. case 2://disappear
  113. {
  114. LEDalpha[iLed] -= disappearShift * 10000;
  115. if (LEDalpha[iLed] <= 0)
  116. {
  117. LEDaction[iLed] = 0;
  118. LEDalpha[iLed] = 0;
  119. LEDtimer[iLed] = -1;
  120. }
  121. int a = 1;
  122. if (a == random(interruptEvery))//durch zufall abbrechen
  123. {
  124. LEDaction[iLed] = 0;
  125. LEDtimer[iLed] = -1;
  126. }
  127. }
  128. break;
  129. }
  130.  
  131. leds[iLed] = CHSV(LEDhue[iLed],(byte)sat, (byte)(((float)LEDalpha[iLed] / 10000) * (float)val));
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment