SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <Adafruit_NeoPixel.h> | |
| 2 | - | Första effekten som fungerar |
| 2 | + | |
| 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 | - | void setup() {
|
| 18 | + | |
| 19 | // Start | |
| 20 | ||
| 21 | void loop() | |
| 22 | {
| |
| 23 | RunningLightsSparkle(0xff,0xff,0x00, 50, 30); | |
| 24 | } | |
| 25 | ||
| 26 | - | void loop() {
|
| 26 | + | void showStrip() |
| 27 | {
| |
| 28 | - | SnowSparkle(0x5, 0x5, 0x5, 30, random(5,100)); |
| 28 | + | |
| 29 | // NeoPixel | |
| 30 | strip.show(); | |
| 31 | - | void SnowSparkle(byte red, byte green, byte blue, int SparkleDelay, int SpeedDelay) {
|
| 31 | + | |
| 32 | ||
| 33 | - | setAll(red,green,blue); |
| 33 | + | |
| 34 | // FastLED | |
| 35 | FastLED.show(); | |
| 36 | #endif | |
| 37 | - | int Pixel = random(NUM_LEDS); |
| 37 | + | |
| 38 | ||
| 39 | - | setPixel(Pixel,0xff,0xff,0xff); |
| 39 | + | void setPixel(int Pixel, byte red, byte green, byte blue) |
| 40 | {
| |
| 41 | #ifdef ADAFRUIT_NEOPIXEL_H | |
| 42 | // NeoPixel | |
| 43 | - | delay(SparkleDelay); |
| 43 | + | |
| 44 | #endif | |
| 45 | - | setPixel(Pixel,red,green,blue); |
| 45 | + | |
| 46 | #ifndef ADAFRUIT_NEOPIXEL_H | |
| 47 | // FastLED | |
| 48 | leds[Pixel].r = red; | |
| 49 | - | delay(SpeedDelay); |
| 49 | + | |
| 50 | leds[Pixel].b = blue; | |
| 51 | #endif | |
| 52 | - | // STOP |
| 52 | + | |
| 53 | - | void showStrip() {
|
| 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 | - | void setPixel(int Pixel, byte red, byte green, byte blue) {
|
| 72 | + | |
| 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 | - | void setAll(byte red, byte green, byte blue) {
|
| 95 | + | |
| 96 | setPixel(Pixel,0xff,0xff,0xff); | |
| 97 | - | for(int i = 0; i < NUM_LEDS; i++ ) {
|
| 97 | + | |
| 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 | - | Sen vill jag lägga till denna effekten. |
| 109 | + | leds[Pixel].g = oG; |
| 110 | leds[Pixel].b = oB; | |
| 111 | - | void loop() {
|
| 111 | + | |
| 112 | - | RunningLights(0xff,0xff,0x00, 50); |
| 112 | + | |
| 113 | delay(WaveDelay); | |
| 114 | } | |
| 115 | - | void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
|
| 115 | + |