/ NeoPixel_Punk_Collar / NeoPixel_Punk_Collar.ino
NeoPixel_Punk_Collar.ino
 1  // SPDX-FileCopyrightText: 2017 Mikey Sklar for Adafruit Industries
 2  //
 3  // SPDX-License-Identifier: MIT
 4  
 5  #include <Adafruit_NeoPixel.h>
 6  
 7  #define PIN 1
 8  
 9  // Parameter 1 = number of pixels in strip
10  // Parameter 2 = Arduino pin number (most are valid)
11  // Parameter 3 = pixel type flags, add together as needed:
12  //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
13  //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
14  //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
15  //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
16  Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, PIN, NEO_RGB + NEO_KHZ800);
17  
18  // IMPORTANT: To reduce NeoPixel burnout risk, avoid connecting
19  // on a live circuit... if you must, connect GND first. Minimize 
20  // distance between Arduino and first pixel.
21  
22  void setup() {
23    strip.begin();
24    strip.show(); // Initialize all pixels to 'off'
25  }
26  
27  void loop() {
28    // Some example procedures showing how to display to the pixels:
29    colorWipe(strip.Color(255, 0, 0), 50); // Red
30    colorWipe(strip.Color(0, 255, 0), 50); // Green
31    colorWipe(strip.Color(0, 0, 255), 50); // Blue
32  
33    rainbow(20);
34    rainbowCycle(20);
35  }
36  
37  // Fill the dots one after the other with a color
38  void colorWipe(uint32_t c, uint8_t wait) {
39    for(uint16_t i=0; i<strip.numPixels(); i++) {
40        strip.setPixelColor(i, c);
41        strip.show();
42        delay(wait);
43    }
44  }
45  
46  void rainbow(uint8_t wait) {
47    uint16_t i, j;
48  
49    for(j=0; j<256; j++) {
50      for(i=0; i<strip.numPixels(); i++) {
51        strip.setPixelColor(i, Wheel((i+j) & 255));
52      }
53      strip.show();
54      delay(wait);
55    }
56  }
57  
58  // Slightly different, this makes the rainbow equally distributed throughout
59  void rainbowCycle(uint8_t wait) {
60    uint16_t i, j;
61  
62    for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
63      for(i=0; i< strip.numPixels(); i++) {
64        strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
65      }
66      strip.show();
67      delay(wait);
68    }
69  }
70  
71  // Input a value 0 to 255 to get a color value.
72  // The colours are a transition r - g - b - back to r.
73  uint32_t Wheel(byte WheelPos) {
74    if(WheelPos < 85) {
75     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
76    } else if(WheelPos < 170) {
77     WheelPos -= 85;
78     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
79    } else {
80     WheelPos -= 170;
81     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
82    }
83  }
84