uwezi icon

dubbel_effekt

uwezi | PRO | 12/18/18 10:32:44 PM UTC | 0 ⭐ | 674 👁️ | Never ⏰ | []
C++ |

2.77 KB

|

None

|

0 👍

/

0 👎

#include <Adafruit_NeoPixel.h>
#define PIN 10
#define NUM_LEDS 60
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
 
void setup() 
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}
// Start
 
void loop() 
{
  RunningLightsSparkle(0xff,0xff,0x00, 50, 30);
}
 
void showStrip() 
{
#ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
#endif
 
#ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
#endif
}
 
void setPixel(int Pixel, byte red, byte green, byte blue) 
{
#ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
 
#ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
#endif
}
 
void setAll(byte red, byte green, byte blue) 
{
  for(int i = 0; i < NUM_LEDS; i++ ) 
  {
    setPixel(i, red, green, blue);
  }
  showStrip();
}
 
void RunningLightsSparkle(byte red, byte green, byte blue, int WaveDelay, int SparkleDelay) 
{
  int Position=0;
  for(int j=0; j<NUM_LEDS*2; j++)
  {
      Position++; // = 0; //Position + Rate;
      for(int i=0; i<NUM_LEDS; i++) 
      {
        // sine wave, 3 offset waves make a rainbow!
        //float level = sin(i+Position) * 127 + 128;
        //setPixel(i,level,0,0);
        //float level = sin(i+Position) * 127 + 128;
        setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                   ((sin(i+Position) * 127 + 128)/255)*green,
                   ((sin(i+Position) * 127 + 128)/255)*blue);
      }
 
      // add sparkle
      int Pixel = random(NUM_LEDS);
 
      // save old color
#ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
      uint32_t color = strip.getPixelColor(Pixel);
#endif
 
#ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
      uint8_t oR = leds[Pixel].r;
      uint8_t oG = leds[Pixel].g;
      uint8_t oB = leds[Pixel].b;
#endif
 
      setPixel(Pixel,0xff,0xff,0xff);
      showStrip();
      delay(SparkleDelay);
      
      // restore old color
#ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
      strip.getPixelColor(Pixel);
#endif
 
#ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
      leds[Pixel].r = oR;
      leds[Pixel].g = oG;
      leds[Pixel].b = oB;
#endif
      showStrip();
      delay(WaveDelay);
  }
}

Comments