Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //***************************************************************
- // Code example for Post-Master Sodium
- // https://plus.google.com/112460818250824432487/posts/4MiomMJAcpF
- //
- // This is a modified version of Erin St Blaine's animated glow
- // scarf code from:
- // https://learn.adafruit.com/animated-neopixel-gemma-glow-fur-scarf/the-code
- //
- //
- // Marc Miller, May 2017
- //***************************************************************
- #include <FastLED.h>
- // Number of hoops, and number of leds in each hoop
- #define NUM_HOOPS 4 // number of hoops in the dress
- #define NUM_HOOP1 8 // how many LEDs in 1st hoop
- #define NUM_HOOP2 8 // how many LEDs in 2nd hoop
- #define NUM_HOOP3 8 // how many LEDs in 3rd hoop
- #define NUM_HOOP4 8 // how many LEDs in 4th hoop
- // Total LEDs in the whole dress, which is the sum of the leds from all hoops
- #define NUM_LEDS NUM_HOOP1 + NUM_HOOP2 + NUM_HOOP3 + NUM_HOOP4
- CRGB leds[NUM_LEDS];
- CRGB leds_temp[NUM_HOOPS]; // Temp array of length NUM_HOOPS for blending colors
- #define DATA_PIN 11
- #define CLOCK_PIN 13
- #define COLOR_ORDER GRB // Try mixing up the letters (RGB, GBR, BRG, etc) for a whole new world of color combinations
- #define BRIGHTNESS 200 // 0-255, higher number is brighter.
- #define SATURATION 255 // 0-255, 0 is pure white, 255 is fully saturated color
- #define SPEED 10 // How fast the colors move. Higher numbers = faster motion
- #define STEPS 10 // How agressive the color gradient is. Lower is smoother transition.
- #define BUTTON_PIN 4 // button is connected to pin 2 and GND
- //---------------------------------------------------------------
- //FastLED comes with several palettes pre-programmed. I like purple a LOT, and so I added a custom purple palette.
- const TProgmemPalette16 PurpleColors_p PROGMEM =
- {
- CRGB::Purple,
- CRGB::Purple,
- CRGB::MidnightBlue,
- CRGB::MidnightBlue,
- CRGB::Purple,
- CRGB::Purple,
- CRGB::BlueViolet,
- CRGB::BlueViolet,
- CRGB::DarkTurquoise,
- CRGB::DarkTurquoise,
- CRGB::DarkBlue,
- CRGB::DarkBlue,
- CRGB::Purple,
- CRGB::Purple,
- CRGB::BlueViolet,
- CRGB::BlueViolet
- };
- //---------------------------------------------------------------
- CRGBPalette16 currentPalette;
- CRGBPalette16 targetPalette( PurpleColors_p );
- TBlendType currentBlending;
- int ledMode = 4; // Starting palette
- unsigned long keyPrevMillis = 0;
- const unsigned long keySampleIntervalMs = 25;
- byte longKeyPressCountMax = 80; // 80 * 25 = 2000 ms
- byte longKeyPressCount = 0;
- byte prevKeyState = HIGH; // button is active low
- //---------------------------------------------------------------
- void setup() {
- Serial.begin(115200);
- delay(3000); // 3 second delay
- FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness( BRIGHTNESS );
- currentBlending =LINEARBLEND;
- pinMode(BUTTON_PIN, INPUT_PULLUP);
- // Check sum of hoop pixels add up to the total number of pixels in dress
- Serial.print("Total number of pixels (ie. NUM_LEDS): "); Serial.println(NUM_LEDS);
- }
- //---------------------------------------------------------------
- void loop() {
- byte currKeyState = digitalRead(BUTTON_PIN);
- if ((prevKeyState == LOW) && (currKeyState == HIGH)) {
- shortKeyPress();
- }
- prevKeyState = currKeyState;
- static uint8_t startIndex = 0;
- startIndex = startIndex + 1; /* motion speed */
- switch (ledMode) {
- case 0:
- currentPalette = HeatColors_p; //Red & Yellow, Fire Colors
- break;
- case 1:
- currentPalette = ForestColors_p; //Foresty greens and yellows
- break;
- case 2:
- currentPalette = OceanColors_p; //Oceans are pretty and filled with mermaids
- break;
- case 3:
- currentPalette = PurpleColors_p; //My custom palette from above
- break;
- case 4:
- currentPalette = RainbowColors_p; //All the colors!
- break;
- case 5:
- currentPalette = RainbowStripeColors_p; //Rainbow stripes
- break;
- case 6:
- currentPalette = PartyColors_p; //All the colors except the greens, which make people look a bit washed out
- break;
- }
- FillLEDsFromPaletteColors( startIndex);
- FillHoops();
- FastLED.show();
- FastLED.delay(1000 / SPEED);
- }
- //---------------------------------------------------------------
- void FillLEDsFromPaletteColors( uint8_t colorIndex) {
- // **modified to use NUM_HOOPS and leds_temp**
- for( int i = 0; i < NUM_HOOPS; i++) {
- leds_temp[i] = ColorFromPalette( currentPalette, colorIndex, BRIGHTNESS, currentBlending);
- colorIndex += STEPS;
- }
- }
- //---------------------------------------------------------------
- void shortKeyPress() {
- ledMode++;
- if (ledMode > 6) {
- ledMode=0;
- }
- }
- //---------------------------------------------------------------
- void FillHoops() {
- //Copy the colors from leds_temp to leds, filling the number of pixels in each hoop
- // start position, number to fill, fill color
- fill_solid(leds, NUM_HOOP1, leds_temp[0]);
- fill_solid(leds+NUM_HOOP1, NUM_HOOP2, leds_temp[1]);
- fill_solid(leds+NUM_HOOP1 + NUM_HOOP2, NUM_HOOP3, leds_temp[2]);
- fill_solid(leds+NUM_HOOP1 + NUM_HOOP2 + NUM_HOOP3, NUM_HOOP4, leds_temp[3]);
- // If there are more of less hoops this will need to be adjusted as needed.
- // Uncomment the below when testing to visualize the leds_temp R,G,B values
- //EVERY_N_SECONDS(1) {
- // Serial.print("leds_temp[0]: "); Serial.print(leds_temp[0].r); Serial.print("\t");
- // Serial.print(leds_temp[0].g); Serial.print("\t"); Serial.println(leds_temp[0].b);
- // Serial.print("leds_temp[1]: "); Serial.print(leds_temp[1].r); Serial.print("\t");
- // Serial.print(leds_temp[1].g); Serial.print("\t"); Serial.println(leds_temp[1].b);
- // Serial.print("leds_temp[2]: "); Serial.print(leds_temp[2].r); Serial.print("\t");
- // Serial.print(leds_temp[2].g); Serial.print("\t"); Serial.println(leds_temp[2].b);
- // Serial.print("leds_temp[3]: "); Serial.print(leds_temp[3].r); Serial.print("\t");
- // Serial.print(leds_temp[3].g); Serial.print("\t"); Serial.println(leds_temp[3].b);
- // Serial.println(" ");
- //}
- }
Add Comment
Please, Sign In to add comment