Guest User

color_Glam FASTLed users

a guest
Feb 1st, 2014
595
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. #include "FastLED.h"
  2. #define NUM_LED 10
  3. CRGB leds[NUM_LED];
  4.  
  5. double LEDalpha[NUM_LED];
  6. int LEDaction[NUM_LED];
  7. int LEDtimer[NUM_LED];
  8.  
  9. int fxLoop;
  10. boolean noColor = 0;
  11. byte hue;
  12. unsigned int loopCount;
  13.  
  14. void setup(){
  15. }
  16.  
  17. void loop(){
  18. color_change_glam(1000, 3, 25, 500, 10000);
  19. }
  20.  
  21. void color_change_glam( int HUEframeRate, byte colorIncrement, byte fadeTimer, int randomCancel, int whiteDuration ) {
  22. randomSeed(0); //creates pseudo-random sequence that repeat exactly
  23. fxLoop++;
  24. for(byte iLed = 0; iLed < NUM_LED; iLed++) {
  25. switch(LEDaction[iLed]){
  26. //action
  27. //nothin
  28. case 0:
  29. {
  30. if (LEDtimer[iLed] == -1){
  31. if (LEDalpha[iLed] == 0){
  32. switch(random(2)){
  33. case 0:
  34. LEDtimer[iLed] = random(fadeTimer);
  35. break; //set timer
  36. case 1:
  37. LEDaction[iLed] = 1;
  38. break;
  39. }
  40. } //appear
  41.  
  42. else if (LEDalpha[iLed] > 0){
  43. switch(random(2)){
  44. case 0:
  45. LEDtimer[iLed] = random(fadeTimer);
  46. break; //set timer
  47. case 1:
  48. LEDaction[iLed] = 2;
  49. break;
  50. }
  51. } //disappear
  52. }
  53. //count down timer
  54. else {
  55. if (LEDtimer[iLed] != -1){
  56. LEDtimer[iLed]--;
  57. }
  58. }
  59. }
  60. break;
  61.  
  62. //action
  63. //appear
  64. case 1:
  65. {
  66. LEDalpha[iLed] += 0.002;
  67. if(LEDalpha[iLed] >= 1){
  68. LEDalpha[iLed] = 1;
  69. LEDaction[iLed] = 0;
  70. LEDtimer[iLed] = -1;
  71. } //is appeared
  72. byte a = 1;
  73. if(a == random(randomCancel)){
  74. LEDaction[iLed] = 0;
  75. LEDtimer[iLed] = -1;
  76. }
  77. } //randomly cancel
  78. break;
  79.  
  80. //action
  81. //disappear
  82. case 2:
  83. {
  84. LEDalpha[iLed] -= 0.005;
  85. if(LEDalpha[iLed] <= 0){
  86. LEDaction[iLed] = 0;
  87. LEDalpha[iLed] = 0;
  88. LEDtimer[iLed] = -1;
  89. } //is disappeared
  90. byte a = 1;
  91. if(a == random(randomCancel)){
  92. LEDaction[iLed] = 0;
  93. LEDtimer[iLed] = -1;
  94. }
  95. } //randomly cancel
  96. break;
  97. }
  98.  
  99. double a = LEDalpha[iLed] * 255;
  100.  
  101. switch(noColor){
  102. case 0:
  103. leds[iLed] = CHSV(hue, 255, a);
  104. break;
  105. case 1:
  106. leds[iLed] = CHSV(hue, 0, a);
  107. break;
  108. }
  109. }
  110.  
  111. LEDS.show();
  112. if(fxLoop > whiteDuration) {
  113. noColor = !noColor;
  114. fxLoop = 0;
  115. }
  116. if(loopCount++ > HUEframeRate){
  117. hue = hue + colorIncrement;
  118. loopCount = 0;
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment