Advertisement
marmil

YUM fun for Matt Richard

Aug 20th, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.47 KB | None | 0 0
  1. // Some YUM fun for Matt Richard to run at Burning Man.
  2. //
  3. // Marc Miller,  Aug 2015
  4. //---------------------------------------------------------------
  5.  
  6. #include "FastLED.h"
  7. #define LED_TYPE LPD8806
  8. #define DATA_PIN 11
  9. #define CLOCK_PIN 13
  10. #define NUM_LEDS 124
  11. #define COLOR_ORDER GRB
  12. #define MASTER_BRIGHTNESS 255
  13. CRGB leds[NUM_LEDS];
  14.  
  15.  
  16. //-----------start of YUM variables------------
  17.     // **** Don't change these variables ****
  18. CHSV leds_vuYUM[NUM_LEDS];
  19. uint8_t hue_highYUM = random8();  // Pick a random initial high hue color.
  20. uint8_t hue_lowYUM = (hue_highYUM + 128);  // Set low to complimentary hue pick.
  21. uint8_t targetYUM[NUM_LEDS];  // Stores target brightness.
  22. unsigned long currentMillisYUM = 0;
  23. unsigned long previousMillisYUM = 0;
  24. uint8_t colorPickYUM;
  25. uint8_t countYUM;
  26. uint8_t deltaYUM;
  27. uint8_t tempYUM;
  28.     // **** OK to change these next four variables ****
  29. uint8_t holdColorYUM = 22;  // Number of seconds to hold color choice.
  30. uint8_t lowCutoffYUM = 55;  // Low brightness minimum. Set to 0 to fade to black.
  31. uint8_t highCutoffYUM = 220;  // Full saturation point when fading up.
  32. uint8_t activityYUM = 5;  // Higher value gives more activity.  Valid range is 0-10.
  33. //-----------end of YUM variables------------
  34.  
  35.  
  36. //---------------------------------------------------------------
  37. void setup() {
  38.   delay(2000);
  39.   FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  40.   FastLED.setBrightness(MASTER_BRIGHTNESS);
  41. }
  42.  
  43.  
  44. //---------------------------------------------------------------
  45. void loop() {
  46.  
  47.   // Check if enough time has passed to change colors.
  48.   currentMillisYUM = millis();
  49.   if ((currentMillisYUM - previousMillisYUM) > (1000*holdColorYUM)) {
  50.     colorPickYUM = random(7);  // Randomly choose color pick.
  51.     colorPickYUM = 6;
  52.     if (colorPickYUM == 0) {
  53.       hue_highYUM = 0;  // red high
  54.       hue_lowYUM = 96;  // green low
  55.     }
  56.     if (colorPickYUM == 1) {
  57.       hue_highYUM = 96;  // green high
  58.       hue_lowYUM = 192;  // purple low
  59.     }
  60.     if (colorPickYUM == 2) {
  61.       hue_highYUM = 84;  // yellow green high
  62.       hue_lowYUM = 56;  // orange low        
  63.     }
  64.     if (colorPickYUM == 3) {
  65.       hue_highYUM = 42;  // lemon high
  66.       hue_lowYUM = 135;  // light blue low
  67.     }
  68.     if (colorPickYUM == 4) {
  69.       hue_highYUM = 192;  // purple high
  70.       hue_lowYUM = 128;  // blue low
  71.     }
  72.     if (colorPickYUM == 5) {
  73.       hue_highYUM = 185;  // blue purple high
  74.       hue_lowYUM = 32;  // orange low
  75.     }
  76.     if (colorPickYUM == 6) {
  77.       hue_highYUM = random8();  // random hue for high
  78.       hue_lowYUM = (hue_highYUM + 128);  // the complimentary hue for low
  79.     }
  80.     previousMillisYUM = currentMillisYUM;
  81.   }
  82.  
  83.   // Assign new random target values whenever count is zero.
  84.   if (countYUM == 0){
  85.     for (int i=0; i < NUM_LEDS/random(1,(11-activityYUM)); i++){
  86.       targetYUM[random8(NUM_LEDS)] = random8(lowCutoffYUM,255);
  87.     }
  88.     countYUM = random8(20,100);  // Pick a new count.  Higher range reduces activity.
  89.   }
  90.  
  91.   // Loop over pixels and check current values against target values.
  92.   for (int i=0; i < NUM_LEDS; i++){
  93.  
  94.     // If less then the target fade up.
  95.     if (leds_vuYUM[i].value < targetYUM[i]){
  96.       deltaYUM = random8(2,9);
  97.       if (leds_vuYUM[i].value + deltaYUM >= targetYUM[i]){
  98.         leds_vuYUM[i].value = targetYUM[i];  // limit to target.
  99.       }
  100.       else { leds_vuYUM[i].value += deltaYUM; }
  101.     }
  102.  
  103.     // Or if greater then the target fade down.
  104.     else {
  105.       deltaYUM = random8(3,5);
  106.       if (leds_vuYUM[i].value - deltaYUM <= targetYUM[i]){
  107.         leds_vuYUM[i].value = targetYUM[i];  // limit to target.
  108.       }
  109.       else { leds_vuYUM[i].value -= deltaYUM; }
  110.     }
  111.  
  112.     // Tweak hue color based on brightness.
  113.     int c_hue = constrain(leds_vuYUM[i].value,lowCutoffYUM,highCutoffYUM);
  114.     leds_vuYUM[i].hue = map(c_hue, lowCutoffYUM, highCutoffYUM, hue_lowYUM, hue_highYUM);
  115.  
  116.     leds_vuYUM[i].saturation = 255;  // Set a saturation value.
  117.     leds[i] = leds_vuYUM[i];  // Copy the HSV leds_vuYUM[] data to the leds[] array.
  118.      
  119.     if (targetYUM[i] > lowCutoffYUM){  // Continously fade target to lowCutoff value.
  120.       targetYUM[i] -= 1;  // Fade by this ammount.
  121.     }
  122.     else { targetYUM[i] = lowCutoffYUM; } // clamp to lowCutoff.
  123.  
  124.   } //end of looping over pixels.
  125.  
  126.   countYUM--;  // Reduce count by one.
  127.   delay(10);  // Slow things down just a bit.
  128.   FastLED.show();  // Display the leds[] array.
  129.  
  130.  
  131. }  //end main loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement