Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FastLED.h"
- #define NUM_LEDS 60
- CRGB leds[NUM_LEDS];
- void setup()
- {
- LEDS.addLeds<WS2811, 2, GRB>(leds, NUM_LEDS);
- //initialize glam with your preferences
- //animationGlam();
- }
- void loop()
- {
- animationGlam();
- LEDS.show();
- }
- int LEDalpha[NUM_LEDS];
- byte LEDaction[NUM_LEDS];
- int LEDtimer[NUM_LEDS];
- byte LEDhue[NUM_LEDS];
- int timerMax = 100;
- byte variation = 0;
- byte variationBase = 0;
- byte sat = 255;
- byte val = 255;
- float appearShift = 0.002;
- float disappearShift = 0.005;
- int interruptEvery = 500;
- void animationGlam(byte _variationBase,byte _variation,float _scatter,float _fadeIn,float _fadeOut)
- {
- variationBase = _variationBase;
- variation = _variation;
- timerMax = _scatter;
- appearShift = _fadeIn;
- disappearShift = _fadeOut;
- animation = 2;
- }
- void animationGlam()
- {
- for (byte iLed = 0; iLed < NUM_LEDS; iLed++)
- {
- switch (LEDaction[iLed])
- {//action
- case 0://nothing
- {
- if (LEDtimer[iLed] == -1)
- {
- if (LEDalpha[iLed] == 0)
- {
- switch (random(2))
- {
- case 0://set timer
- LEDtimer[iLed] = random(timerMax);
- break;
- case 1://appear
- LEDaction[iLed] = 1;
- break;
- }
- }
- else if (LEDalpha[iLed] > 0)
- {
- switch (random(2))
- {
- case 0://set timer
- LEDtimer[iLed] = random(timerMax);
- break;
- case 1://disappear
- LEDaction[iLed] = 2;
- break;
- }
- }
- }
- else
- {//timer runter zählen
- if (LEDtimer[iLed] != -1)
- {
- LEDtimer[iLed]--;
- }
- }
- }
- break;
- case 1://appear
- {
- //Farbe durch zufall wählen
- if (LEDalpha[iLed] == 0)
- {
- LEDhue[iLed] = (byte)(variationBase + random(variation));
- }
- LEDalpha[iLed] += appearShift * 10000;
- if (LEDalpha[iLed] >= 10000) //ist erschienen
- {
- LEDalpha[iLed] = 10000;
- LEDaction[iLed] = 0;
- LEDtimer[iLed] = -1;
- }
- int a = 1;
- if (a == random(interruptEvery))//durch zufall abbrechen
- {
- LEDaction[iLed] = 0;
- LEDtimer[iLed] = -1;
- }
- }
- break;
- case 2://disappear
- {
- LEDalpha[iLed] -= disappearShift * 10000;
- if (LEDalpha[iLed] <= 0)
- {
- LEDaction[iLed] = 0;
- LEDalpha[iLed] = 0;
- LEDtimer[iLed] = -1;
- }
- int a = 1;
- if (a == random(interruptEvery))//durch zufall abbrechen
- {
- LEDaction[iLed] = 0;
- LEDtimer[iLed] = -1;
- }
- }
- break;
- }
- leds[iLed] = CHSV(LEDhue[iLed],(byte)sat, (byte)(((float)LEDalpha[iLed] / 10000) * (float)val));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment