/ Mystical_LED_Halloween_Hood / Mystical_LED_Halloween_Hood.ino
Mystical_LED_Halloween_Hood.ino
1 // SPDX-FileCopyrightText: 2017 Tony Sherwood for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 //fades all pixels subtly 6 //code by Tony Sherwood for Adafruit Industries 7 8 #include <Adafruit_NeoPixel.h> 9 10 #define PIN 1 11 12 // Parameter 1 = number of pixels in strip 13 // Parameter 2 = pin number (most are valid) 14 // Parameter 3 = pixel type flags, add together as needed: 15 // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) 16 // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) 17 // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) 18 // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) 19 Adafruit_NeoPixel strip = Adafruit_NeoPixel(14, PIN, NEO_GRB + NEO_KHZ800); 20 21 int alpha; // Current value of the pixels 22 int dir = 1; // Direction of the pixels... 1 = getting brighter, 0 = getting dimmer 23 int flip; // Randomly flip the direction every once in a while 24 int minAlpha = 25; // Min value of brightness 25 int maxAlpha = 100; // Max value of brightness 26 int alphaDelta = 5; // Delta of brightness between times through the loop 27 28 void setup() { 29 strip.begin(); 30 strip.show(); // Initialize all pixels to 'off' 31 } 32 33 void loop() { 34 flip = random(32); 35 if(flip > 20) { 36 dir = 1 - dir; 37 } 38 // Some example procedures showing how to display to the pixels: 39 if (dir == 1) { 40 alpha += alphaDelta; 41 } 42 if (dir == 0) { 43 alpha -= alphaDelta; 44 } 45 if (alpha < minAlpha) { 46 alpha = minAlpha; 47 dir = 1; 48 } 49 if (alpha > maxAlpha) { 50 alpha = maxAlpha; 51 dir = 0; 52 } 53 // Change the line below to alter the color of the lights 54 // The numbers represent the Red, Green, and Blue values 55 // of the lights, as a value between 0(off) and 1(max brightness) 56 // 57 // EX: 58 // colorSet(strip.Color(alpha, 0, alpha/2)); // Pink 59 //colorSet(strip.Color(0, 0, alpha)); // Blue 60 //colorSet(strip.Color(alpha, alpha/2, 0)); // Yellow 61 colorSet(strip.Color(alpha, 0, 0)); // Red 62 } 63 64 // Fill the dots one after the other with a color 65 void colorSet(uint32_t c) { 66 for(uint16_t i=0; i<strip.numPixels(); i++) { 67 strip.setPixelColor(i, c); 68 strip.show(); 69 } 70 }