Last active
November 11, 2016 07:45
-
-
Save Husqvarna450/670d6188da0e4162b42c31653051d326 to your computer and use it in GitHub Desktop.
First_Tests_v1
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 150 | |
#define NUM_LEDS_LEFT 45 | |
#define NUM_LEDS_MIDDLE 21 | |
#define NUM_LEDS_RIGHT 45 | |
#define FRAMES_PER_SECOND 120 | |
//CRGB leds1[NUM_LEDS]; | |
CRGBArray < NUM_LEDS > leds; | |
CRGBSet left(leds(0, 44)); //set custom ranges left 45 middle 20 right 45 | |
CRGBSet middle(leds(45, 65)); | |
CRGBSet right(leds(66, 111)); | |
CRGBSet all(leds(0, 111)); | |
//CRGBSet all(leds(0,111)); | |
long lastchangemillis = 0; // Count for hold3randomcolors | |
long interval = 3000; // 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( TypicalSMD5050 ); | |
// FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds1, NUM_LEDS).setCorrection( TypicalSMD5050 ); | |
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(); | |
Serial.println(randomeffect); | |
if (randomeffect <= 255 * 0.5) { | |
Serial.println("picked randomcolors"); | |
make3randomcolors (); | |
run3colors (); | |
show3colors (); | |
} | |
else { | |
Serial.println("picked randomgradient"); | |
randomgradient (); | |
} | |
// FastLED.show(); | |
} | |
//delay(2000); //Test_Delay | |
} | |
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 = random8 (); | |
randomvat = random8 (180, 255); // generate Random vat | |
} | |
void show3colors () { | |
//FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalSMD5050 ); | |
Serial.println("show3colors random1 value:"); | |
Serial.println(random1); | |
CHSV color1hsv(random1, randomvat, brightness); //write colors with random saturation and global brightness | |
CHSV color2hsv(random2, randomvat, brightness); | |
CHSV color3hsv(random3, randomvat, brightness); | |
left = color1hsv; | |
middle = color2hsv; | |
right = color3hsv; | |
FastLED.show(); Serial.println("show3colors fastledshow"); | |
} | |
void run3colors () { | |
//FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalSMD5050 ); | |
Serial.println("run3colors random1 value:"); | |
Serial.println(random1); | |
CHSV color1hsv(random1, randomvat, brightness); //write colors with random saturation and global brightness | |
CHSV color2hsv(random2, randomvat, brightness); | |
CHSV color3hsv(random3, randomvat, brightness); | |
int delayrun = 8; | |
for (int k = 0; k <= NUM_LEDS_LEFT ; k++) { | |
leds[k] = color1hsv; | |
for(int i = 1; i<=10 ; i++){ leds[k+i]=CHSV (random1, randomvat, 10*i);} | |
FastLED.show(); | |
delay(delayrun); | |
} | |
for (int k = NUM_LEDS_LEFT; k <= NUM_LEDS_LEFT + NUM_LEDS_MIDDLE ; k++) { | |
leds[k] = color2hsv; | |
for(int i = 1; i<=10 ; i++){ leds[k+i]=CHSV (random2, randomvat, 10*i/2);} | |
FastLED.show(); | |
delay(delayrun); | |
} | |
for (int k = NUM_LEDS_MIDDLE + NUM_LEDS_LEFT; k <= NUM_LEDS ; k++) { | |
leds[k] = color3hsv; | |
for(int i = 1; i<=10 ; i++){ leds[k+i]=CHSV (random3, randomvat, 10*i);} | |
FastLED.show(); | |
delay(delayrun); | |
} | |
leds(0, 111) = color1hsv; | |
middle = color2hsv; | |
right = color3hsv; | |
FastLED.show(); Serial.println("show3colors fastledshow"); | |
} | |
void randomgradient () { | |
//FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalSMD5050 ); | |
//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 (190, 255); // generate Random vat1 | |
randomvat2 = random8 (190, 255); // generate Random vat2 | |
CHSV gradStartColorCHSV(random1, randomvat1, brightness); // Gradient start color. | |
CHSV gradEndColorCHSV(random2, randomvat2, brightness); // Gradient end color. | |
CRGB gradStartColorCRGB(random1, randomvat1, random2); | |
CRGB gradEndColorCRGB(random2,random1,randomvat2); | |
hsv2rgb_rainbow( gradStartColorCHSV, gradStartColorCRGB); | |
hsv2rgb_rainbow( gradEndColorCHSV, gradEndColorCRGB); | |
//all = gradStartColorCRGB; | |
fill_gradient(leds, 0, gradStartColorCRGB, NUM_LEDS-2, gradEndColorCRGB, LONGEST_HUES); | |
FastLED.show(); Serial.println("fill_gradient fastledshow"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment