rainbow.ino
 1  // SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
 2  //
 3  // SPDX-License-Identifier: MIT
 4  
 5  #include <Adafruit_DotStar.h>
 6  
 7  #define NUM_DOTSTAR 5
 8  
 9  // LEDs!
10  Adafruit_DotStar pixels(NUM_DOTSTAR, PIN_DOTSTAR_DATA, PIN_DOTSTAR_CLOCK, DOTSTAR_BRG);
11  
12  uint16_t firstPixelHue = 0;
13  uint8_t LED_dutycycle = 0;
14  
15  void setup() {
16    Serial.begin(115200);
17    
18    pinMode(LED_BUILTIN, OUTPUT);
19    
20    ledcSetup(0, 5000, 8);
21    ledcAttachPin(LED_BUILTIN, 0);
22    
23    pixels.begin(); // Initialize pins for output
24    pixels.show();  // Turn all LEDs off ASAP
25    pixels.setBrightness(20);
26  }
27  
28  
29  
30  void loop() {
31    Serial.println("Hello!");
32  
33    // pulse red LED
34    ledcWrite(0, LED_dutycycle++);
35  
36    // rainbow dotstars
37    for (int i=0; i<pixels.numPixels(); i++) { // For each pixel in strip...
38        int pixelHue = firstPixelHue + (i * 65536L / pixels.numPixels());
39        pixels.setPixelColor(i, pixels.gamma32(pixels.ColorHSV(pixelHue)));
40    }
41    pixels.show(); // Update strip with new contents
42    firstPixelHue += 256;
43  
44    delay(15);
45  }
46  
47  
48  void rainbow(int wait) {
49    for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
50      for(int i=0; i<pixels.numPixels(); i++) { // For each pixel in strip...
51        int pixelHue = firstPixelHue + (i * 65536L / pixels.numPixels());
52        pixels.setPixelColor(i, pixels.gamma32(pixels.ColorHSV(pixelHue)));
53      }
54      pixels.show(); // Update strip with new contents
55      delay(wait);  // Pause for a moment
56    }
57  }