/ Gemma_Hoop_Earrings / Gemma_Hoop_Earrings.ino
Gemma_Hoop_Earrings.ino
 1  // SPDX-FileCopyrightText: 2017 Phillip Burgess for Adafruit Industries
 2  //
 3  // SPDX-License-Identifier: MIT
 4  
 5  // Low power NeoPixel earrings example.  Makes a nice blinky display
 6  // with just a few LEDs on at any time...uses MUCH less juice than
 7  // rainbow display!
 8  
 9  #include <Adafruit_NeoPixel.h>
10  
11  #define PIN       0
12  #define NUM_LEDS 16
13  
14  Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN);
15  
16  uint8_t  mode   = 0,        // Current animation effect
17           offset = 0;        // Position of spinner animation
18  uint32_t color  = 0xFF8000; // Starting color = amber
19  uint32_t prevTime;          // Time of last animation mode switch
20  
21  void setup() {
22    pixels.begin();
23    pixels.setBrightness(60); // ~1/3 brightness
24    prevTime = millis();      // Starting time
25  }
26  
27  void loop() {
28    uint8_t  i;
29    uint32_t t;
30  
31    switch(mode) {
32  
33     case 0: // Random sparkles - just one LED on at a time!
34      i = random(NUM_LEDS);           // Choose a random pixel
35      pixels.setPixelColor(i, color); // Set it to current color
36      pixels.show();                  // Refresh LED states
37      // Set same pixel to "off" color now but DON'T refresh...
38      // it stays on for now...both this and the next random
39      // pixel will be refreshed on the next pass.
40      pixels.setPixelColor(i, 0);
41      delay(10);                      // 10 millisecond delay
42      break;
43   
44     case 1: // Spinny wheel (4 LEDs on at a time)
45      for(i=0; i<NUM_LEDS; i++) {    // For each LED...
46        uint32_t c = 0;              // Assume pixel will be "off" color
47        if(((offset + i) & 7) < 2) { // For each 8 pixels, 2 will be...
48          c = color;                 // ...assigned the current color
49        }
50        pixels.setPixelColor(i, c);  // Set color of pixel 'i'
51      }
52      pixels.show();                 // Refresh LED states
53      delay(50);                     // 50 millisecond delay
54      offset++;                      // Shift animation by 1 pixel on next frame
55      break;
56  
57      // More animation modes could be added here!
58    }
59  
60    t = millis();                    // Current time in milliseconds
61    if((t - prevTime) > 8000) {      // Every 8 seconds...
62      mode++;                        // Advance to next animation mode
63      if(mode > 1) {                 // End of modes?
64        mode = 0;                    // Start over from beginning
65        color >>= 8;                 // And change color
66        if(!color) color = 0xFF8000; // preiodically reset to amber
67      }
68      pixels.clear();                // Set all pixels to 'off' state
69      prevTime = t;                  // Record the time of the last mode change
70    }
71  }