/ 3D_Printed_Unicorn_Horn / 3D_Printed_Unicorn_Horn.ino
3D_Printed_Unicorn_Horn.ino
 1  // SPDX-FileCopyrightText: 2015 Phil Burgess 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(8, PIN, NEO_GRB + NEO_KHZ800);
17  
18  // IMPORTANT: Avoid connecting on a live circuit...if you must, connect GND first.
19  
20  void setup() {
21    strip.begin();
22    strip.setBrightness(100); //adjust brightness here
23    strip.show(); // Initialize all pixels to 'off'
24  }
25  
26  void loop() {
27    rainbowCycle(20);
28  }
29  
30  
31  // Slightly different, this makes the rainbow equally distributed throughout
32  void rainbowCycle(uint8_t wait) {
33    uint16_t i, j;
34  
35    for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
36      for(i=0; i< strip.numPixels(); i++) {
37        strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
38      }
39      strip.show();
40      delay(wait);
41    }
42  }
43  
44  
45  
46  // Input a value 0 to 255 to get a color value.
47  // The colours are a transition r - g - b - back to r.
48  uint32_t Wheel(byte WheelPos) {
49    if(WheelPos < 85) {
50     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
51    } else if(WheelPos < 170) {
52     WheelPos -= 85;
53     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
54    } else {
55     WheelPos -= 170;
56     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
57    }
58  }
59