marmil

hoop dress example

May 14th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.29 KB | None | 0 0
  1. //***************************************************************
  2. // Code example for Post-Master Sodium
  3. // https://plus.google.com/112460818250824432487/posts/4MiomMJAcpF
  4. //
  5. // This is a modified version of Erin St Blaine's animated glow
  6. // scarf code from:
  7. // https://learn.adafruit.com/animated-neopixel-gemma-glow-fur-scarf/the-code
  8. //
  9. //
  10. // Marc Miller, May 2017
  11. //***************************************************************
  12.  
  13. #include <FastLED.h>
  14.  
  15. // Number of hoops, and number of leds in each hoop
  16. #define NUM_HOOPS   4  // number of hoops in the dress
  17. #define NUM_HOOP1   8  // how many LEDs in 1st hoop
  18. #define NUM_HOOP2   8  // how many LEDs in 2nd hoop
  19. #define NUM_HOOP3   8  // how many LEDs in 3rd hoop
  20. #define NUM_HOOP4   8  // how many LEDs in 4th hoop
  21.  
  22. // Total LEDs in the whole dress, which is the sum of the leds from all hoops
  23. #define NUM_LEDS    NUM_HOOP1 + NUM_HOOP2 + NUM_HOOP3 + NUM_HOOP4
  24.  
  25. CRGB leds[NUM_LEDS];
  26. CRGB leds_temp[NUM_HOOPS];  // Temp array of length NUM_HOOPS for blending colors
  27.  
  28. #define DATA_PIN 11
  29. #define CLOCK_PIN 13
  30. #define COLOR_ORDER GRB  // Try mixing up the letters (RGB, GBR, BRG, etc) for a whole new world of color combinations
  31. #define BRIGHTNESS 200  // 0-255, higher number is brighter.
  32. #define SATURATION 255  // 0-255, 0 is pure white, 255 is fully saturated color
  33. #define SPEED       10  // How fast the colors move.  Higher numbers = faster motion
  34. #define STEPS       10  // How agressive the color gradient is.  Lower is smoother transition.
  35. #define BUTTON_PIN   4  // button is connected to pin 2 and GND
  36.  
  37.  
  38. //---------------------------------------------------------------
  39. //FastLED comes with several palettes pre-programmed.  I like purple a LOT, and so I added a custom purple palette.
  40.  
  41. const TProgmemPalette16 PurpleColors_p PROGMEM =
  42. {
  43.   CRGB::Purple,
  44.   CRGB::Purple,
  45.   CRGB::MidnightBlue,
  46.   CRGB::MidnightBlue,
  47.  
  48.   CRGB::Purple,
  49.   CRGB::Purple,
  50.   CRGB::BlueViolet,
  51.   CRGB::BlueViolet,
  52.  
  53.   CRGB::DarkTurquoise,
  54.   CRGB::DarkTurquoise,
  55.   CRGB::DarkBlue,
  56.   CRGB::DarkBlue,
  57.  
  58.   CRGB::Purple,
  59.   CRGB::Purple,
  60.   CRGB::BlueViolet,
  61.   CRGB::BlueViolet
  62. };
  63.  
  64. //---------------------------------------------------------------
  65. CRGBPalette16 currentPalette;
  66. CRGBPalette16 targetPalette( PurpleColors_p );
  67. TBlendType    currentBlending;
  68. int ledMode = 4;  // Starting palette
  69.  
  70. unsigned long keyPrevMillis = 0;
  71. const unsigned long keySampleIntervalMs = 25;
  72. byte longKeyPressCountMax = 80;    // 80 * 25 = 2000 ms
  73. byte longKeyPressCount = 0;
  74.  
  75. byte prevKeyState = HIGH;         // button is active low
  76.  
  77.  
  78. //---------------------------------------------------------------
  79. void setup() {
  80.   Serial.begin(115200);
  81.   delay(3000);  // 3 second delay
  82.   FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  83.   FastLED.setBrightness(  BRIGHTNESS );
  84.   currentBlending =LINEARBLEND;
  85.   pinMode(BUTTON_PIN, INPUT_PULLUP);
  86.  
  87.   // Check sum of hoop pixels add up to the total number of pixels in dress
  88.   Serial.print("Total number of pixels (ie. NUM_LEDS):  "); Serial.println(NUM_LEDS);
  89. }
  90.  
  91.  
  92. //---------------------------------------------------------------
  93. void loop() {
  94.  
  95.   byte currKeyState = digitalRead(BUTTON_PIN);
  96.  
  97.   if ((prevKeyState == LOW) && (currKeyState == HIGH)) {
  98.     shortKeyPress();
  99.   }
  100.   prevKeyState = currKeyState;
  101.  
  102.   static uint8_t startIndex = 0;
  103.   startIndex = startIndex + 1; /* motion speed */
  104.  
  105.   switch (ledMode) {
  106.  
  107.   case 0:
  108.     currentPalette = HeatColors_p;    //Red & Yellow, Fire Colors
  109.     break;
  110.   case 1:
  111.     currentPalette = ForestColors_p;    //Foresty greens and yellows
  112.     break;
  113.   case 2:
  114.     currentPalette = OceanColors_p;  //Oceans are pretty and filled with mermaids
  115.     break;
  116.   case 3:
  117.     currentPalette = PurpleColors_p;  //My custom palette from above
  118.     break;
  119.   case 4:
  120.     currentPalette = RainbowColors_p;  //All the colors!
  121.     break;
  122.   case 5:
  123.     currentPalette = RainbowStripeColors_p;   //Rainbow stripes
  124.     break;      
  125.   case 6:
  126.     currentPalette = PartyColors_p; //All the colors except the greens, which make people look a bit washed out
  127.     break;
  128.   }
  129.  
  130.   FillLEDsFromPaletteColors( startIndex);
  131.   FillHoops();
  132.   FastLED.show();
  133.   FastLED.delay(1000 / SPEED);  
  134. }
  135.  
  136.  
  137. //---------------------------------------------------------------
  138. void FillLEDsFromPaletteColors( uint8_t colorIndex) {
  139.   // **modified to use NUM_HOOPS and leds_temp**
  140.   for( int i = 0; i < NUM_HOOPS; i++) {
  141.     leds_temp[i] = ColorFromPalette( currentPalette, colorIndex, BRIGHTNESS, currentBlending);
  142.     colorIndex += STEPS;              
  143.   }
  144. }
  145.  
  146.  
  147. //---------------------------------------------------------------
  148. void shortKeyPress() {
  149.   ledMode++;
  150.   if (ledMode > 6) {
  151.     ledMode=0;
  152.   }  
  153. }
  154.  
  155.  
  156. //---------------------------------------------------------------
  157. void FillHoops() {
  158.   //Copy the colors from leds_temp to leds, filling the number of pixels in each hoop
  159.   //                start position,                 number to fill,   fill color
  160.   fill_solid(leds,                                    NUM_HOOP1,      leds_temp[0]);
  161.   fill_solid(leds+NUM_HOOP1,                          NUM_HOOP2,      leds_temp[1]);
  162.   fill_solid(leds+NUM_HOOP1 + NUM_HOOP2,              NUM_HOOP3,      leds_temp[2]);
  163.   fill_solid(leds+NUM_HOOP1 + NUM_HOOP2 + NUM_HOOP3,  NUM_HOOP4,      leds_temp[3]);
  164.   // If there are more of less hoops this will need to be adjusted as needed.
  165.  
  166.   // Uncomment the below when testing to visualize the leds_temp R,G,B values
  167.     //EVERY_N_SECONDS(1) {
  168.     //  Serial.print("leds_temp[0]:  "); Serial.print(leds_temp[0].r); Serial.print("\t");
  169.     //    Serial.print(leds_temp[0].g); Serial.print("\t"); Serial.println(leds_temp[0].b);
  170.     //  Serial.print("leds_temp[1]:  "); Serial.print(leds_temp[1].r); Serial.print("\t");
  171.     //    Serial.print(leds_temp[1].g); Serial.print("\t"); Serial.println(leds_temp[1].b);
  172.     //  Serial.print("leds_temp[2]:  "); Serial.print(leds_temp[2].r); Serial.print("\t");
  173.     //    Serial.print(leds_temp[2].g); Serial.print("\t"); Serial.println(leds_temp[2].b);
  174.     //  Serial.print("leds_temp[3]:  "); Serial.print(leds_temp[3].r); Serial.print("\t");
  175.     //    Serial.print(leds_temp[3].g); Serial.print("\t"); Serial.println(leds_temp[3].b);
  176.     //  Serial.println(" ");
  177.     //}
  178.  
  179. }
Add Comment
Please, Sign In to add comment