Guest User

Untitled

a guest
Oct 26th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.42 KB | None | 0 0
  1. //FADE
  2.         //_____________________________________________________________________________________
  3.         //Slowly fade from on color to another. Due to more "flow" LED n + 1 is faded to half at the same time
  4.         //first while to enter the effect
  5.         while (effect == 0)
  6.         {  
  7.             //some stuff that should be done only once
  8.             uint8_t fadeState = 0;
  9.             uint8_t actualLed = 0;
  10.            
  11.             //second while, the actual effect
  12.             while (effect == 0)
  13.             {
  14.                 //initiate for this effect
  15.                 if (initiated == 0)
  16.                 {  
  17.                     //set all LEDs to red
  18.                     for (int i = 0; i < numLeds; i++)
  19.                     {
  20.                         color[i * 3] = 255;
  21.                         color[(i * 3) + 1] = 0;
  22.                         color[(i * 3) + 2] = 0;
  23.                     }
  24.                    
  25.                     color[0] = 127;
  26.                     color[2] = 127;
  27.                    
  28.                     ws2801_sendRGB(color, numLeds);
  29.                    
  30.                     //enter normal Effect-Mode
  31.                     initiated = 1;
  32.                     fadeState = 1;
  33.                 }
  34.                
  35.                 else
  36.                 {
  37.                     //fade to green
  38.                     if (initiated == 1 && fadeState == 1)
  39.                     {
  40.                         for (int j = 0; j < 127; j++)
  41.                         {
  42.                             //actual LED
  43.                             color[actualLed * 3] = 127 - j;
  44.                             color[(actualLed * 3) + 2] = 127 + j;
  45.                            
  46.                             //next LED
  47.                             if (((actualLed + 1) % numLeds) != 0)
  48.                             {
  49.                                 color[((actualLed + 1) % numLeds) * 3] = 255 - j;
  50.                                 color[(((actualLed + 1) % numLeds) * 3) + 2] = 0 + j;
  51.                             }
  52.                             else //first LED reached
  53.                             {
  54.                                 color[((actualLed + 1) % numLeds) * 3] = 0 + j;
  55.                                 color[(((actualLed + 1) % numLeds) * 3) + 2] = 255 - j;
  56.                             }
  57.                            
  58.                            
  59.                             ws2801_sendRGB(color, numLeds);
  60.                             long_delay(15);
  61.                         }
  62.                     }
  63.                    
  64.                     //fade to red
  65.                     if (initiated == 1 && fadeState == 2)
  66.                     {
  67.                         for (int j = 0; j < 127; j++)
  68.                         {
  69.                             //actual LED
  70.                             color[actualLed * 3] = 127 + j;
  71.                             color[(actualLed * 3) + 2] = 127 - j;
  72.                            
  73.                             //next LED
  74.                             if (((actualLed + 1) % numLeds) != 0)
  75.                             {
  76.                                 color[((actualLed + 1) % numLeds) * 3] = 0 + j;
  77.                                 color[(((actualLed + 1) % numLeds) * 3) + 2] = 255 - j;
  78.                             }
  79.                             else //first LED reached
  80.                             {
  81.                                 color[((actualLed + 1) % numLeds) * 3] = 255 - j;
  82.                                 color[(((actualLed + 1) % numLeds) * 3) + 2] = 0 + j;
  83.                             }
  84.  
  85.                            
  86.                             ws2801_sendRGB(color, numLeds);
  87.                             long_delay(15);
  88.                         }
  89.                     }
  90.                 }
  91.                
  92.                 //jump to next LED/fade-color
  93.                 actualLed = (actualLed + 1) % numLeds;
  94.                 if (actualLed == 0)
  95.                 fadeState = (fadeState % 2) + 1;
  96.             }
Advertisement
Add Comment
Please, Sign In to add comment