/ NeoPixel_Basketball_Hoop / NeoPixel_Basketball_Hoop / NeoPixel_Basketball_Hoop.ino
NeoPixel_Basketball_Hoop.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  Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
10  
11  void setup() {
12    strip.begin();
13    strip.show(); // Initialize all pixels to 'off'
14  }
15  
16  void loop() {
17    // Some example procedures showing how to display to the pixels:
18    colorWipe(strip.Color(255, 0, 0), 50); // Red
19    colorWipe(strip.Color(0, 255, 0), 50); // Green
20    colorWipe(strip.Color(0, 0, 255), 50); // Blue
21    rainbow(20);
22    rainbowCycle(20);
23  }
24  
25  // Fill the dots one after the other with a color
26  void colorWipe(uint32_t c, uint8_t wait) {
27    for(uint16_t i=0; i<strip.numPixels(); i++) {
28        strip.setPixelColor(i, c);
29        strip.show();
30        delay(wait);
31    }
32  }
33  
34  void rainbow(uint8_t wait) {
35    uint16_t i, j;
36  
37    for(j=0; j<256; j++) {
38      for(i=0; i<strip.numPixels(); i++) {
39        strip.setPixelColor(i, Wheel((i+j) & 255));
40      }
41      strip.show();
42      delay(wait);
43    }
44  }
45  
46  // Slightly different, this makes the rainbow equally distributed throughout
47  void rainbowCycle(uint8_t wait) {
48    uint16_t i, j;
49  
50    for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
51      for(i=0; i< strip.numPixels(); i++) {
52        strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
53      }
54      strip.show();
55      delay(wait);
56    }
57  }
58  
59  // Input a value 0 to 255 to get a color value.
60  // The colours are a transition r - g - b - back to r.
61  uint32_t Wheel(byte WheelPos) {
62    if(WheelPos < 85) {
63     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
64    } else if(WheelPos < 170) {
65     WheelPos -= 85;
66     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
67    } else {
68     WheelPos -= 170;
69     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
70    }
71  }