G2A Many GEOs
SHARE
TWEET

Ripple for FastLED Library

atuline Aug 4th, 2014 7,176 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Ripple
  2. //
  3. // Converted (but not optimized) from the Neopixel version https://gist.github.com/suhajdab/9716635
  4. //
  5. // Conversion by Andrew Tuline
  6. //
  7.  
  8.  
  9. #include <FastLED.h>        // FastLED library
  10.  
  11.  
  12. #define LED_DT 13
  13. #define NUM_LEDS 24
  14.  
  15. struct CRGB leds[NUM_LEDS];
  16.  
  17. int color;
  18. int center = 0;
  19. int step = -1;
  20. int maxSteps = 16;
  21. float fadeRate = 0.8;
  22. int diff;
  23.  
  24. //background color
  25. uint32_t currentBg = random(256);
  26. uint32_t nextBg = currentBg;
  27.  
  28. void setup() {
  29.  
  30.   Serial.begin(9600);
  31.   LEDS.addLeds<WS2811, LED_DT, GRB>(leds, NUM_LEDS);
  32.  
  33. }
  34.  
  35. void loop () {
  36.   ripple();
  37. }
  38.  
  39. void ripple() {
  40.  
  41.     if (currentBg == nextBg) {
  42.       nextBg = random(256);
  43.     }
  44.     else if (nextBg > currentBg) {
  45.       currentBg++;
  46.     } else {
  47.       currentBg--;
  48.     }
  49.     for(uint16_t l = 0; l < NUM_LEDS; l++) {
  50.       leds[l] = CHSV(currentBg, 255, 50);         // strip.setPixelColor(l, Wheel(currentBg, 0.1));
  51.     }
  52.  
  53.   if (step == -1) {
  54.     center = random(NUM_LEDS);
  55.     color = random(256);
  56.     step = 0;
  57.   }
  58.  
  59.   if (step == 0) {
  60.     leds[center] = CHSV(color, 255, 255);         // strip.setPixelColor(center, Wheel(color, 1));
  61.     step ++;
  62.   }
  63.   else {
  64.     if (step < maxSteps) {
  65.       Serial.println(pow(fadeRate,step));
  66.  
  67.       leds[wrap(center + step)] = CHSV(color, 255, pow(fadeRate, step)*255);       //   strip.setPixelColor(wrap(center + step), Wheel(color, pow(fadeRate, step)));
  68.       leds[wrap(center - step)] = CHSV(color, 255, pow(fadeRate, step)*255);       //   strip.setPixelColor(wrap(center - step), Wheel(color, pow(fadeRate, step)));
  69.       if (step > 3) {
  70.         leds[wrap(center + step - 3)] = CHSV(color, 255, pow(fadeRate, step - 2)*255);     //   strip.setPixelColor(wrap(center + step - 3), Wheel(color, pow(fadeRate, step - 2)));
  71.         leds[wrap(center - step + 3)] = CHSV(color, 255, pow(fadeRate, step - 2)*255);     //   strip.setPixelColor(wrap(center - step + 3), Wheel(color, pow(fadeRate, step - 2)));
  72.       }
  73.       step ++;
  74.     }
  75.     else {
  76.       step = -1;
  77.     }
  78.   }
  79.  
  80.   LEDS.show();
  81.   delay(50);
  82. }
  83.  
  84.  
  85. int wrap(int step) {
  86.   if(step < 0) return NUM_LEDS + step;
  87.   if(step > NUM_LEDS - 1) return step - NUM_LEDS;
  88.   return step;
  89. }
  90.  
  91.  
  92. void one_color_allHSV(int ahue, int abright) {                // SET ALL LEDS TO ONE COLOR (HSV)
  93.   for (int i = 0 ; i < NUM_LEDS; i++ ) {
  94.     leds[i] = CHSV(ahue, 255, abright);
  95.   }
  96. }
  97.  
  98.  
  99.  
  100. // Input a value 0 to 255 to get a color value.
  101. // The colours are a transition r - g - b - back to r.
  102. /* uint32_t Wheel(byte WheelPos, float opacity) {
  103.  
  104.   if(WheelPos < 85) {
  105.     return strip.Color((WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity, 0);
  106.   }
  107.   else if(WheelPos < 170) {
  108.     WheelPos -= 85;
  109.     return strip.Color((255 - WheelPos * 3) * opacity, 0, (WheelPos * 3) * opacity);
  110.   }
  111.   else {
  112.     WheelPos -= 170;
  113.     return strip.Color(0, (WheelPos * 3) * opacity, (255 - WheelPos * 3) * opacity);
  114.   }
  115. }
  116. */
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top