/ NeoPixel_Jewel_10_Minute_Necklace / NeoPixel_Jewel_10_Minute_Necklace.ino
NeoPixel_Jewel_10_Minute_Necklace.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 pixels = Adafruit_NeoPixel(40, PIN);
 10  
 11  uint8_t  mode   = 0, // Current animation effect
 12           offset = 0;
 13  uint32_t color  = 0X00A4B3; // Starting color
 14  uint32_t prevTime; 
 15  
 16  void setup() {
 17    pixels.begin();
 18    pixels.setBrightness(40); // 1/3 brightness
 19    prevTime = millis();
 20  }
 21  
 22  void loop() {
 23    uint8_t  i;
 24    uint32_t t;
 25  
 26    switch(mode) {
 27      
 28     case 0: //rainbow hold
 29      rainbowHold(20);
 30      delay(500);
 31      break;
 32      
 33     case 1: //rainbow cycle slow
 34      rainbowCycleslow(20);
 35      delay(50);
 36      break;
 37         
 38     case 2: //rainbow cycle fast 
 39      rainbowCycle(5);
 40      delay(50);
 41      break;
 42    }
 43  
 44    t = millis();
 45    if((t - prevTime) > 8000) {      // Every 8 seconds...
 46      mode++;                        // Next mode
 47      if(mode > 3) {                 // End of modes?
 48        mode = 0;                    // Start modes over
 49        color >>= 8;                 // Next color R->G->B
 50        if(!color) color = 0xB300A4; // Reset color
 51      }
 52      for(i=0; i<32; i++) pixels.setPixelColor(i, 0);
 53      prevTime = t;
 54      
 55    }
 56  
 57    
 58  }
 59  void rainbow(uint8_t wait) {
 60    uint16_t i, j;
 61  
 62    for(j=0; j<256; j++) {
 63      for(i=0; i<pixels.numPixels(); i++) {
 64        pixels.setPixelColor(i, Wheel((i+j) & 255));
 65      }
 66      pixels.show();
 67      delay(wait);
 68    }
 69  }
 70  
 71  void rainbowCycle(uint8_t wait) {
 72    uint16_t r, j;
 73  
 74    for(j=0; j<256*6; j++) { // 6 cycles of all colors on wheel
 75      for(r=0; r< pixels.numPixels(); r++) {
 76        pixels.setPixelColor(r, Wheel(((r * 256 / pixels.numPixels()) + j) & 255));
 77      }
 78      pixels.show();
 79      delay(wait);
 80    }
 81  }
 82  void rainbowCycleslow(uint8_t wait) {
 83    uint16_t r, j;
 84  
 85    for(j=0; j<256*3; j++) { // 3 cycles of all colors on wheel
 86      for(r=0; r< pixels.numPixels(); r++) {
 87        pixels.setPixelColor(r, Wheel(((r * 256 / pixels.numPixels()) + j) & 255));
 88      }
 89      pixels.show();
 90      delay(wait);
 91    }
 92  }
 93  void rainbowHold(uint8_t wait) {
 94    uint16_t r, j;
 95  
 96    for(j=0; j<256*1; j++) { // 3 cycles of all colors on wheel
 97      for(r=0; r< pixels.numPixels(); r++) {
 98        pixels.setPixelColor(r, Wheel(((r * 256 / pixels.numPixels()) + j) & 255));
 99      }
100      pixels.show();
101      delay(wait);
102    }
103  }
104  
105  // Input a value 0 to 255 to get a color value.
106  // The colours are a transition r - g - b - back to r.
107  uint32_t Wheel(byte WheelPos) {
108    if(WheelPos < 85) {
109     return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
110    } else if(WheelPos < 170) {
111     WheelPos -= 85;
112     return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
113    } else {
114     WheelPos -= 170;
115     return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
116    }
117  }
118