Created
November 9, 2016 11:16
-
-
Save anonymous/aac730f23cc49ac9679dc8dd1feeee8a to your computer and use it in GitHub Desktop.
My_first_FASTLed_project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <FastLED.h> | |
#define LED_PIN 6 | |
#define COLOR_ORDER RGB | |
#define CHIPSET WS2812B | |
#define NUM_LEDS 111 | |
#define BRIGHTNESS 140 | |
#define FRAMES_PER_SECOND 120 | |
CRGB leds[NUM_LEDS]; | |
CRGBArray < NUM_LEDS > ledsarray; | |
CRGBSet left(ledsarray(0, 44)); //set custom ranges left 45 middle 20 right 45 | |
CRGBSet middle(ledsarray(45, 65)); | |
CRGBSet right(ledsarray(66, 111)); | |
CRGB ledsright(ledsarray(66, 111)); | |
long lastchangemillis = 0; // Count for hold3randomcolors | |
int interval = 6000; // Duration for hold3randomcolors | |
int random1 = 130; // Random colors for hold3randomcolors | |
int random2 = 50; | |
int random3 = 200; | |
int randomvat = 255; | |
int randomvat1; | |
int randomvat2; | |
int randomvat3; | |
int oldrandom1; | |
int oldrandom2; | |
int oldrandom3; | |
int oldrandomvat; | |
int brightness = (BRIGHTNESS); | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("resetting"); | |
delay(1000); // sanity delay | |
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); | |
FastLED.setBrightness( BRIGHTNESS ); | |
Serial.print("Setup Complete"); | |
} | |
void loop() { | |
unsigned long currentmillis = millis(); //Serial.println("currentmillis"); Serial.println(currentmillis); Serial.println("lastchangemillis"); Serial.println(lastchangemillis); | |
if (currentmillis - lastchangemillis >= interval) { | |
Serial.println("colorchange"); | |
lastchangemillis = currentmillis; | |
int randomeffect = random8(); | |
if (randomeffect <= 255 * 0.5) { | |
make3randomcolors (); | |
show3colors (); | |
} | |
else { | |
randomgradient (); | |
} | |
FastLED.show(); | |
} | |
} | |
void make3randomcolors () { | |
//delay(50); | |
//Serial.println("random1"); Serial.println(random1); Serial.println("random2"); Serial.println(random2); Serial.println("random3"); Serial.println(random3); | |
random1 = random8 (); // generate Random Numbers (0..255) for random hue | |
random2 = random1 + random8 (50, 205); | |
random3 = random2 + random8 (50, 205); | |
randomvat = random8 (180, 255); // generate Random vat | |
} | |
void show3colors () { | |
CHSV color1hsv(random1, randomvat, brightness); //write colors with random saturation and global brightness | |
CHSV color2hsv(random2, randomvat, brightness); | |
CHSV color3hsv(random3, randomvat, brightness); | |
FastLED.show(); | |
} | |
void randomgradient () { | |
//delay(50); | |
//Serial.println("random1"); Serial.println(random1); Serial.println("random2"); Serial.println(random2); | |
random1 = random8 (); // generate Random Numbers (0..255) for random hue | |
random2 = random1 + random8 (55, 200); | |
randomvat1 = random8 (140, 255); // generate Random vat1 | |
randomvat2 = random8 (140, 255); // generate Random vat2 | |
fill_gradient(leds, 0, CHSV(random1, randomvat1, brightness), NUM_LEDS, CHSV(random2, randomvat2, brightness), SHORTEST_HUES); | |
FastLED.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment