Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //FADE
- //_____________________________________________________________________________________
- //Slowly fade from on color to another. Due to more "flow" LED n + 1 is faded to half at the same time
- //first while to enter the effect
- while (effect == 0)
- {
- //some stuff that should be done only once
- uint8_t fadeState = 0;
- uint8_t actualLed = 0;
- //second while, the actual effect
- while (effect == 0)
- {
- //initiate for this effect
- if (initiated == 0)
- {
- //set all LEDs to red
- for (int i = 0; i < numLeds; i++)
- {
- color[i * 3] = 255;
- color[(i * 3) + 1] = 0;
- color[(i * 3) + 2] = 0;
- }
- color[0] = 127;
- color[2] = 127;
- ws2801_sendRGB(color, numLeds);
- //enter normal Effect-Mode
- initiated = 1;
- fadeState = 1;
- }
- else
- {
- //fade to green
- if (initiated == 1 && fadeState == 1)
- {
- for (int j = 0; j < 127; j++)
- {
- //actual LED
- color[actualLed * 3] = 127 - j;
- color[(actualLed * 3) + 2] = 127 + j;
- //next LED
- if (((actualLed + 1) % numLeds) != 0)
- {
- color[((actualLed + 1) % numLeds) * 3] = 255 - j;
- color[(((actualLed + 1) % numLeds) * 3) + 2] = 0 + j;
- }
- else //first LED reached
- {
- color[((actualLed + 1) % numLeds) * 3] = 0 + j;
- color[(((actualLed + 1) % numLeds) * 3) + 2] = 255 - j;
- }
- ws2801_sendRGB(color, numLeds);
- long_delay(15);
- }
- }
- //fade to red
- if (initiated == 1 && fadeState == 2)
- {
- for (int j = 0; j < 127; j++)
- {
- //actual LED
- color[actualLed * 3] = 127 + j;
- color[(actualLed * 3) + 2] = 127 - j;
- //next LED
- if (((actualLed + 1) % numLeds) != 0)
- {
- color[((actualLed + 1) % numLeds) * 3] = 0 + j;
- color[(((actualLed + 1) % numLeds) * 3) + 2] = 255 - j;
- }
- else //first LED reached
- {
- color[((actualLed + 1) % numLeds) * 3] = 255 - j;
- color[(((actualLed + 1) % numLeds) * 3) + 2] = 0 + j;
- }
- ws2801_sendRGB(color, numLeds);
- long_delay(15);
- }
- }
- }
- //jump to next LED/fade-color
- actualLed = (actualLed + 1) % numLeds;
- if (actualLed == 0)
- fadeState = (fadeState % 2) + 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment