Created
February 7, 2017 12:09
-
-
Save ivoras/bdeae148df082e9db5f92a02b2a3516e to your computer and use it in GitHub Desktop.
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 PIN_PANEL 10 | |
#define N_LEDS 64 | |
#define BRIGHTNESS 255 | |
#define FPS 120 | |
CRGB leds[N_LEDS]; | |
CRGB source_leds[N_LEDS]; | |
CRGB target_leds[N_LEDS]; | |
#define N_NICE_COLORS 7 | |
//CRGB nice_colors[7] = { CRGB(0xf0, 0, 0), CRGB(0xff, 0x66, 0), CRGB(0xff, 0x60, 0), CRGB(0x10, 0x8, 0), CRGB(5, 0, 0), CRGB(0, 0, 0), CRGB(0, 0, 0) }; | |
CRGB nice_colors[7] = { CRGB(0xf0, 0, 0), CRGB(0xff-0x30, 0x66-0x30, 0), CRGB(0xaf, 0x60, 0), CRGB(0x10, 0x8, 0), CRGB(5, 0, 0), CRGB(0, 0, 0), CRGB(0, 0, 0) }; | |
CRGB black = CRGB(0, 0, 0); | |
fract8 lerp_factor = 0; | |
uint32_t stm = 0; | |
uint32_t now = 0; | |
uint16_t fcount = 0; | |
void fill_nice_colors(CRGB *arr) { | |
for (byte i = 0; i < N_LEDS; i++) { | |
arr[i] = nice_colors[random(N_NICE_COLORS)]; | |
} | |
} | |
void fade_leds() { | |
for (byte i = 0; i < N_LEDS; i++) { | |
leds[i] = source_leds[i].lerp8(target_leds[i], lerp_factor); | |
} | |
if (lerp_factor < 255) { | |
lerp_factor++; | |
return; | |
} | |
memcpy(&source_leds, &target_leds, sizeof(source_leds)); | |
fill_nice_colors(target_leds); | |
for (byte i = 0; i < N_LEDS; i++) { | |
while (source_leds[i] == black && target_leds[i] == black) { | |
target_leds[i] = nice_colors[random(N_NICE_COLORS)]; | |
} | |
} | |
lerp_factor = 0; | |
} | |
void add_sparkle() { | |
for (byte i = 0; i < N_LEDS; i++) { | |
if (random(10000) < 2) | |
leds[i] = CRGB(0xff, 0xff, 0xff); | |
} | |
} | |
void setup() { | |
FastLED.addLeds<WS2812B, PIN_PANEL, GRB>(leds, N_LEDS).setCorrection(TypicalLEDStrip); | |
//FastLED.setBrightness(BRIGHTNESS); | |
randomSeed(analogRead(0)); | |
fill_nice_colors(target_leds); | |
/* Serial.begin(9600); | |
while (!Serial) {}*/ | |
} | |
void loop() { | |
now = millis(); | |
fade_leds(); | |
//add_sparkle(); | |
FastLED.show(); | |
FastLED.delay(2); | |
fcount++; | |
/* | |
if (now - stm >= 1000) { | |
Serial.println(fcount); | |
fcount = 0; | |
stm = now; | |
}*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment