Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Some YUM fun for Matt Richard to run at Burning Man.
- //
- // Marc Miller, Aug 2015
- //---------------------------------------------------------------
- #include "FastLED.h"
- #define LED_TYPE LPD8806
- #define DATA_PIN 11
- #define CLOCK_PIN 13
- #define NUM_LEDS 124
- #define COLOR_ORDER GRB
- #define MASTER_BRIGHTNESS 255
- CRGB leds[NUM_LEDS];
- //-----------start of YUM variables------------
- // **** Don't change these variables ****
- CHSV leds_vuYUM[NUM_LEDS];
- uint8_t hue_highYUM = random8(); // Pick a random initial high hue color.
- uint8_t hue_lowYUM = (hue_highYUM + 128); // Set low to complimentary hue pick.
- uint8_t targetYUM[NUM_LEDS]; // Stores target brightness.
- unsigned long currentMillisYUM = 0;
- unsigned long previousMillisYUM = 0;
- uint8_t colorPickYUM;
- uint8_t countYUM;
- uint8_t deltaYUM;
- uint8_t tempYUM;
- // **** OK to change these next four variables ****
- uint8_t holdColorYUM = 22; // Number of seconds to hold color choice.
- uint8_t lowCutoffYUM = 55; // Low brightness minimum. Set to 0 to fade to black.
- uint8_t highCutoffYUM = 220; // Full saturation point when fading up.
- uint8_t activityYUM = 5; // Higher value gives more activity. Valid range is 0-10.
- //-----------end of YUM variables------------
- //---------------------------------------------------------------
- void setup() {
- delay(2000);
- FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
- FastLED.setBrightness(MASTER_BRIGHTNESS);
- }
- //---------------------------------------------------------------
- void loop() {
- // Check if enough time has passed to change colors.
- currentMillisYUM = millis();
- if ((currentMillisYUM - previousMillisYUM) > (1000*holdColorYUM)) {
- colorPickYUM = random(7); // Randomly choose color pick.
- colorPickYUM = 6;
- if (colorPickYUM == 0) {
- hue_highYUM = 0; // red high
- hue_lowYUM = 96; // green low
- }
- if (colorPickYUM == 1) {
- hue_highYUM = 96; // green high
- hue_lowYUM = 192; // purple low
- }
- if (colorPickYUM == 2) {
- hue_highYUM = 84; // yellow green high
- hue_lowYUM = 56; // orange low
- }
- if (colorPickYUM == 3) {
- hue_highYUM = 42; // lemon high
- hue_lowYUM = 135; // light blue low
- }
- if (colorPickYUM == 4) {
- hue_highYUM = 192; // purple high
- hue_lowYUM = 128; // blue low
- }
- if (colorPickYUM == 5) {
- hue_highYUM = 185; // blue purple high
- hue_lowYUM = 32; // orange low
- }
- if (colorPickYUM == 6) {
- hue_highYUM = random8(); // random hue for high
- hue_lowYUM = (hue_highYUM + 128); // the complimentary hue for low
- }
- previousMillisYUM = currentMillisYUM;
- }
- // Assign new random target values whenever count is zero.
- if (countYUM == 0){
- for (int i=0; i < NUM_LEDS/random(1,(11-activityYUM)); i++){
- targetYUM[random8(NUM_LEDS)] = random8(lowCutoffYUM,255);
- }
- countYUM = random8(20,100); // Pick a new count. Higher range reduces activity.
- }
- // Loop over pixels and check current values against target values.
- for (int i=0; i < NUM_LEDS; i++){
- // If less then the target fade up.
- if (leds_vuYUM[i].value < targetYUM[i]){
- deltaYUM = random8(2,9);
- if (leds_vuYUM[i].value + deltaYUM >= targetYUM[i]){
- leds_vuYUM[i].value = targetYUM[i]; // limit to target.
- }
- else { leds_vuYUM[i].value += deltaYUM; }
- }
- // Or if greater then the target fade down.
- else {
- deltaYUM = random8(3,5);
- if (leds_vuYUM[i].value - deltaYUM <= targetYUM[i]){
- leds_vuYUM[i].value = targetYUM[i]; // limit to target.
- }
- else { leds_vuYUM[i].value -= deltaYUM; }
- }
- // Tweak hue color based on brightness.
- int c_hue = constrain(leds_vuYUM[i].value,lowCutoffYUM,highCutoffYUM);
- leds_vuYUM[i].hue = map(c_hue, lowCutoffYUM, highCutoffYUM, hue_lowYUM, hue_highYUM);
- leds_vuYUM[i].saturation = 255; // Set a saturation value.
- leds[i] = leds_vuYUM[i]; // Copy the HSV leds_vuYUM[] data to the leds[] array.
- if (targetYUM[i] > lowCutoffYUM){ // Continously fade target to lowCutoff value.
- targetYUM[i] -= 1; // Fade by this ammount.
- }
- else { targetYUM[i] = lowCutoffYUM; } // clamp to lowCutoff.
- } //end of looping over pixels.
- countYUM--; // Reduce count by one.
- delay(10); // Slow things down just a bit.
- FastLED.show(); // Display the leds[] array.
- } //end main loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement