Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define NUM_LED 10
- CRGB leds[NUM_LED];
- double LEDalpha[NUM_LED];
- int LEDaction[NUM_LED];
- int LEDtimer[NUM_LED];
- int fxLoop;
- boolean noColor = 0;
- byte hue;
- unsigned int loopCount;
- void setup(){
- }
- void loop(){
- color_change_glam(1000, 3, 25, 500, 10000);
- }
- void color_change_glam( int HUEframeRate, byte colorIncrement, byte fadeTimer, int randomCancel, int whiteDuration ) {
- randomSeed(0); //creates pseudo-random sequence that repeat exactly
- fxLoop++;
- for(byte iLed = 0; iLed < NUM_LED; iLed++) {
- switch(LEDaction[iLed]){
- //action
- //nothin
- case 0:
- {
- if (LEDtimer[iLed] == -1){
- if (LEDalpha[iLed] == 0){
- switch(random(2)){
- case 0:
- LEDtimer[iLed] = random(fadeTimer);
- break; //set timer
- case 1:
- LEDaction[iLed] = 1;
- break;
- }
- } //appear
- else if (LEDalpha[iLed] > 0){
- switch(random(2)){
- case 0:
- LEDtimer[iLed] = random(fadeTimer);
- break; //set timer
- case 1:
- LEDaction[iLed] = 2;
- break;
- }
- } //disappear
- }
- //count down timer
- else {
- if (LEDtimer[iLed] != -1){
- LEDtimer[iLed]--;
- }
- }
- }
- break;
- //action
- //appear
- case 1:
- {
- LEDalpha[iLed] += 0.002;
- if(LEDalpha[iLed] >= 1){
- LEDalpha[iLed] = 1;
- LEDaction[iLed] = 0;
- LEDtimer[iLed] = -1;
- } //is appeared
- byte a = 1;
- if(a == random(randomCancel)){
- LEDaction[iLed] = 0;
- LEDtimer[iLed] = -1;
- }
- } //randomly cancel
- break;
- //action
- //disappear
- case 2:
- {
- LEDalpha[iLed] -= 0.005;
- if(LEDalpha[iLed] <= 0){
- LEDaction[iLed] = 0;
- LEDalpha[iLed] = 0;
- LEDtimer[iLed] = -1;
- } //is disappeared
- byte a = 1;
- if(a == random(randomCancel)){
- LEDaction[iLed] = 0;
- LEDtimer[iLed] = -1;
- }
- } //randomly cancel
- break;
- }
- double a = LEDalpha[iLed] * 255;
- switch(noColor){
- case 0:
- leds[iLed] = CHSV(hue, 255, a);
- break;
- case 1:
- leds[iLed] = CHSV(hue, 0, a);
- break;
- }
- }
- LEDS.show();
- if(fxLoop > whiteDuration) {
- noColor = !noColor;
- fxLoop = 0;
- }
- if(loopCount++ > HUEframeRate){
- hue = hue + colorIncrement;
- loopCount = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment