/ Superhero_Power_Plant / Superhero_Power_Plant.ino
Superhero_Power_Plant.ino
 1  // SPDX-FileCopyrightText: 2017 Tony Sherwood for Adafruit Industries
 2  //
 3  // SPDX-License-Identifier: MIT
 4  
 5  //Superhero Power Plant
 6  //fades all pixels subtly
 7  //code by Tony Sherwood for Adafruit Industries
 8  
 9  #include <Adafruit_NeoPixel.h>
10  
11  #define PIN 1
12  
13  // Parameter 1 = number of pixels in strip
14  // Parameter 2 = pin number (most are valid)
15  // Parameter 3 = pixel type flags, add together as needed:
16  //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
17  //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
18  //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
19  //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
20  Adafruit_NeoPixel strip = Adafruit_NeoPixel(17, PIN, NEO_GRB + NEO_KHZ800);
21  
22  int alpha; // Current value of the pixels
23  int dir = 1; // Direction of the pixels... 1 = getting brighter, 0 = getting dimmer
24  int flip; // Randomly flip the direction every once in a while
25  int minAlpha = 25; // Min value of brightness
26  int maxAlpha = 100; // Max value of brightness
27  int alphaDelta = 5; // Delta of brightness between times through the loop
28  
29  void setup() {
30    strip.begin();
31    strip.show(); // Initialize all pixels to 'off'
32  }
33  
34  void loop() {
35    flip = random(32);
36    if(flip > 20) {
37      dir = 1 - dir;
38    }
39    // Some example procedures showing how to display to the pixels:
40    if (dir == 1) {
41      alpha += alphaDelta;
42    }
43    if (dir == 0) {
44      alpha -= alphaDelta;
45    }
46    if (alpha < minAlpha) {
47      alpha = minAlpha;
48      dir = 1;
49    }
50    if (alpha > maxAlpha) {
51      alpha = maxAlpha;
52      dir = 0;
53    }
54    // Change the line below to alter the color of the lights
55    // The numbers represent the Red, Green, and Blue values
56    // of the lights, as a value between 0(off) and 1(max brightness)
57    //
58    // EX:
59    // colorWipe(strip.Color(alpha, 0, alpha/2)); // Pink
60    colorWipe(strip.Color(0, 0, alpha)); // Blue
61  }
62  
63  // Fill the dots one after the other with a color
64  void colorWipe(uint32_t c) {
65    for(uint16_t i=0; i<strip.numPixels(); i++) {
66        strip.setPixelColor(i, c);
67        strip.show();
68    }
69  }