/ Animated_NeoPixel_Glow_Fur_Scarf / Animated_NeoPixel_Glow_Fur_Scarf.ino
Animated_NeoPixel_Glow_Fur_Scarf.ino
1 // SPDX-FileCopyrightText: 2018 Mikey Sklar for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 #include <FastLED.h> 6 7 #define LED_PIN 1 // which pin your pixels are connected to 8 #define NUM_LEDS 78 // how many LEDs you have 9 #define BRIGHTNESS 200 // 0-255, higher number is brighter. 10 #define SATURATION 255 // 0-255, 0 is pure white, 255 is fully saturated color 11 #define SPEED 10 // How fast the colors move. Higher numbers = faster motion 12 #define STEPS 2 // How wide the bands of color are. 1 = more like a gradient, 10 = more like stripes 13 #define BUTTON_PIN 2 // button is connected to pin 2 and GND 14 15 #define COLOR_ORDER GRB // Try mixing up the letters (RGB, GBR, BRG, etc) for a whole new world of color combinations 16 17 CRGB leds[NUM_LEDS]; 18 CRGBPalette16 currentPalette; 19 CRGBPalette16 targetPalette( PartyColors_p ); 20 TBlendType currentBlending; 21 int ledMode = 0; 22 23 24 //FastLED comes with several palettes pre-programmed. I like purple a LOT, and so I added a custom purple palette. 25 26 const TProgmemPalette16 PurpleColors_p PROGMEM = 27 { 28 CRGB::Purple, 29 CRGB::Purple, 30 CRGB::MidnightBlue, 31 CRGB::MidnightBlue, 32 33 CRGB::Purple, 34 CRGB::Purple, 35 CRGB::BlueViolet, 36 CRGB::BlueViolet, 37 38 CRGB::DarkTurquoise, 39 CRGB::DarkTurquoise, 40 CRGB::DarkBlue, 41 CRGB::DarkBlue, 42 43 CRGB::Purple, 44 CRGB::Purple, 45 CRGB::BlueViolet, 46 CRGB::BlueViolet 47 }; 48 49 50 unsigned long keyPrevMillis = 0; 51 const unsigned long keySampleIntervalMs = 25; 52 byte longKeyPressCountMax = 80; // 80 * 25 = 2000 ms 53 byte longKeyPressCount = 0; 54 55 byte prevKeyState = HIGH; // button is active low 56 57 void setup() { 58 delay( 2000 ); // power-up safety delay 59 FastLED.addLeds<WS2812B, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); 60 FastLED.setBrightness( BRIGHTNESS ); 61 currentBlending =LINEARBLEND; 62 pinMode(BUTTON_PIN, INPUT_PULLUP); 63 } 64 65 void loop() { 66 67 byte currKeyState = digitalRead(BUTTON_PIN); 68 69 if ((prevKeyState == LOW) && (currKeyState == HIGH)) { 70 shortKeyPress(); 71 } 72 prevKeyState = currKeyState; 73 74 static uint8_t startIndex = 0; 75 startIndex = startIndex + 1; /* motion speed */ 76 77 switch (ledMode) { 78 79 case 0: 80 currentPalette = HeatColors_p; //Red & Yellow, Fire Colors 81 break; 82 case 1: 83 currentPalette = ForestColors_p; //Foresty greens and yellows 84 break; 85 case 2: 86 currentPalette = OceanColors_p; //Oceans are pretty and filled with mermaids 87 break; 88 case 3: 89 currentPalette = PurpleColors_p; //My custom palette from above 90 break; 91 case 4: 92 currentPalette = RainbowColors_p; //All the colors! 93 break; 94 case 5: 95 currentPalette = RainbowStripeColors_p; //Rainbow stripes 96 break; 97 case 6: 98 currentPalette = PartyColors_p; //All the colors except the greens, which make people look a bit washed out 99 break; 100 } 101 102 FillLEDsFromPaletteColors( startIndex); 103 FastLED.show(); 104 FastLED.delay(1000 / SPEED); 105 } 106 107 void FillLEDsFromPaletteColors( uint8_t colorIndex) { 108 for( int i = 0; i < NUM_LEDS; i++) { 109 leds[i] = ColorFromPalette( currentPalette, colorIndex, BRIGHTNESS, currentBlending); 110 colorIndex += STEPS; 111 } 112 } 113 114 void shortKeyPress() { 115 ledMode++; 116 if (ledMode > 6) { 117 ledMode=0; 118 } 119 }