uwezi

dubbel_effekt

Dec 18th, 2018
164
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_NeoPixel.h>
  2. #define PIN 10
  3. #define NUM_LEDS 60
  4. // Parameter 1 = number of pixels in strip
  5. // Parameter 2 = pin number (most are valid)
  6. // Parameter 3 = pixel type flags, add together as needed:
  7. //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  8. //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  9. //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  10. //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  11.  
  12. Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
  13.  
  14. void setup()
  15. {
  16.   strip.begin();
  17.   strip.show(); // Initialize all pixels to 'off'
  18. }
  19. // Start
  20.  
  21. void loop()
  22. {
  23.   RunningLightsSparkle(0xff,0xff,0x00, 50, 30);
  24. }
  25.  
  26. void showStrip()
  27. {
  28. #ifdef ADAFRUIT_NEOPIXEL_H
  29.    // NeoPixel
  30.    strip.show();
  31. #endif
  32.  
  33. #ifndef ADAFRUIT_NEOPIXEL_H
  34.    // FastLED
  35.    FastLED.show();
  36. #endif
  37. }
  38.  
  39. void setPixel(int Pixel, byte red, byte green, byte blue)
  40. {
  41. #ifdef ADAFRUIT_NEOPIXEL_H
  42.    // NeoPixel
  43.    strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  44. #endif
  45.  
  46. #ifndef ADAFRUIT_NEOPIXEL_H
  47.    // FastLED
  48.    leds[Pixel].r = red;
  49.    leds[Pixel].g = green;
  50.    leds[Pixel].b = blue;
  51. #endif
  52. }
  53.  
  54. void setAll(byte red, byte green, byte blue)
  55. {
  56.   for(int i = 0; i < NUM_LEDS; i++ )
  57.   {
  58.     setPixel(i, red, green, blue);
  59.   }
  60.   showStrip();
  61. }
  62.  
  63. void RunningLightsSparkle(byte red, byte green, byte blue, int WaveDelay, int SparkleDelay)
  64. {
  65.   int Position=0;
  66.   for(int j=0; j<NUM_LEDS*2; j++)
  67.   {
  68.       Position++; // = 0; //Position + Rate;
  69.       for(int i=0; i<NUM_LEDS; i++)
  70.       {
  71.         // sine wave, 3 offset waves make a rainbow!
  72.         //float level = sin(i+Position) * 127 + 128;
  73.         //setPixel(i,level,0,0);
  74.         //float level = sin(i+Position) * 127 + 128;
  75.         setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
  76.                    ((sin(i+Position) * 127 + 128)/255)*green,
  77.                    ((sin(i+Position) * 127 + 128)/255)*blue);
  78.       }
  79.  
  80.       // add sparkle
  81.       int Pixel = random(NUM_LEDS);
  82.  
  83.       // save old color
  84. #ifdef ADAFRUIT_NEOPIXEL_H
  85.    // NeoPixel
  86.       uint32_t color = strip.getPixelColor(Pixel);
  87. #endif
  88.  
  89. #ifndef ADAFRUIT_NEOPIXEL_H
  90.    // FastLED
  91.       uint8_t oR = leds[Pixel].r;
  92.       uint8_t oG = leds[Pixel].g;
  93.       uint8_t oB = leds[Pixel].b;
  94. #endif
  95.  
  96.       setPixel(Pixel,0xff,0xff,0xff);
  97.       showStrip();
  98.       delay(SparkleDelay);
  99.      
  100.       // restore old color
  101. #ifdef ADAFRUIT_NEOPIXEL_H
  102.    // NeoPixel
  103.       strip.getPixelColor(Pixel);
  104. #endif
  105.  
  106. #ifndef ADAFRUIT_NEOPIXEL_H
  107.    // FastLED
  108.       leds[Pixel].r = oR;
  109.       leds[Pixel].g = oG;
  110.       leds[Pixel].b = oB;
  111. #endif
  112.       showStrip();
  113.       delay(WaveDelay);
  114.   }
  115. }
RAW Paste Data