#include <FastLED.h>
#define NUM_LEDS 180
#define LED_PIN 3
//CRGB leds[NUM_LEDS];
CRGBArray <NUM_LEDS> leds;
uint8_t data[ NUM_LEDS];
void setup() {
delay(3000);
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(100);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000);
randomSeed(analogRead(A0));
}
void loop() {
int seqVar = random(0, 2);
//uint32_t period2 = .1 * 60000L; // X minutes
uint32_t period2 = random(10,20) * 1000L; // X seconds
for ( uint32_t tStart = millis(); (millis() - tStart) < period2; )
switch (seqVar) {
case 0:
//uint32_t period2 = .1 * 60000L; // X minutes
//for ( uint32_t tStart = millis(); (millis() - tStart) < period2; )
movingDotred();
break;
case 1:
//uint32_t period2 = .2 * 60000L; // X minutes
//for ( uint32_t tStart = millis(); (millis() - tStart) < period2; )
movingDotwhite();
break;
case 2:
//uint32_t period2 = .2 * 60000L; // X minutes
//for ( uint32_t tStart = millis(); (millis() - tStart) < period2; )
movingDotblue();
break;
case 3:
//uint32_t period3 = .3 * 60000L; // X minutes
//for ( uint32_t tStart = millis(); (millis() - tStart) < period2; )
phaseBeat();
break;
case 4:
//uint32_t period3 = .3 * 60000L; // X minutes
//for ( uint32_t tStart = millis(); (millis() - tStart) < period2; )
redwhitebluestripeswithglitter();
break;
case 5:
//uint32_t period3 = .3 * 60000L; // X minutes
//for ( uint32_t tStart = millis(); (millis() - tStart) < period2; )
RWBFadeInandOut();
break;
case 6:
//uint32_t period3 = .3 * 60000L; // X minutes
//for ( uint32_t tStart = millis(); (millis() - tStart) < period2; )
NewKITT(0xff, 0, 0, 35, .1, 50);
NewKITT(0, 0, 0xff, 35, .1, 50);
NewKITT(0xff, 0xff, 0xff, 35, .1, 50);
break;
case 7:
//uint32_t period3 = .3 * 60000L; // X minutes
//for ( uint32_t tStart = millis(); (millis() - tStart) < period2; )
theaterChase(0xff, 0, 0, 70);
theaterChase(0xff, 0xff, 0xff, 70);
theaterChase(0, 0, 0xff, 70);
break;
case 8:
outsideinmeteors();
break;
default:
;
}
}
void movingDotred() {
uint16_t sinBeat = beatsin16(20, 0, NUM_LEDS - 1, 0, 0);
leds[sinBeat] = CRGB::Red;
fadeToBlackBy(leds, NUM_LEDS, 10);
FastLED.show();
}
void movingDotwhite() {
uint16_t sinBeat = beatsin16(20, 0, NUM_LEDS - 1, 0, 0);
leds[sinBeat] = CRGB::White;
fadeToBlackBy(leds, NUM_LEDS, 10);
FastLED.show();
}
void movingDotblue() {
uint16_t sinBeat = beatsin16(20, 0, NUM_LEDS - 1, 0, 0);
leds[sinBeat] = CRGB::Blue;
fadeToBlackBy(leds, NUM_LEDS, 10);
FastLED.show();
}
void phaseBeat() {
// uint8_t sinBeat = beatsin8(15, 0, NUM_LEDS - 1, 0, 0);
// uint8_t sinBeat2 = beatsin8(15, 0, NUM_LEDS - 1, 0, 85);
// uint8_t sinBeat3 = beatsin8(15, 0, NUM_LEDS - 1, 0, 170);
// If you notice that your pattern is missing out certain LEDs, you
// will need to use the higher resolution beatsin16 instead. In this
// case remove the 3 lines above and replace them with the following:
uint16_t sinBeat = beatsin16(15, 0, NUM_LEDS - 1, 0, 0);
uint16_t sinBeat2 = beatsin16(15, 0, NUM_LEDS - 1, 0, 21845);
uint16_t sinBeat3 = beatsin16(15, 0, NUM_LEDS - 1, 0, 43690);
leds[sinBeat] = CRGB::Blue;
leds[sinBeat2] = CRGB::Red;
leds[sinBeat3] = CRGB::White;
fadeToBlackBy(leds, NUM_LEDS, 10);
FastLED.show();
}
void redwhitebluestripeswithglitter() {
fill_data_array();
render_data_with_palette();
add_glitter();
FastLED.show();
FastLED.delay(20);
}
void fill_data_array()
{
static uint8_t startValue = 0;
startValue = startValue + 2;
uint8_t value = startValue;
for ( int i = 0; i < NUM_LEDS; i++) {
data[i] = triwave8( value); // convert value to an up-and-down wave
value += 3;
}
}
CRGBPalette16 gPalette (
CRGB::Black, CRGB::Black,
CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,
CRGB::Gray, CRGB::Gray, CRGB::Gray, CRGB::Gray,
CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,
CRGB::Black, CRGB::Black
);
void render_data_with_palette()
{
for ( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( gPalette, data[i], 128, LINEARBLEND);
}
}
void add_glitter()
{
int chance_of_glitter = 10; // percent of the time that we add glitter
int number_of_glitters = 10; // number of glitter sparkles to add
int r = random8(100);
if ( r < chance_of_glitter ) {
for ( int j = 0; j < number_of_glitters; j++) {
int pos = random16( NUM_LEDS);
leds[pos] = CRGB::White; // very bright glitter
}
}
}
void RWBFadeInandOut() {
FadeInOut(0xff, 0x00, 0x00); // red
FadeInOut(0xff, 0xff, 0xff); // white
FadeInOut(0x00, 0x00, 0xff); // blue
}
void setAll(byte red, byte white, byte blue) {
for (int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, white, blue);
}
FastLED.show();
}
void setPixel(int Pixel, byte red, byte white, byte blue) {
leds[Pixel].r = red;
leds[Pixel].g = white;
leds[Pixel].b = blue;
}
void FadeInOut(byte red, byte green, byte blue) {
float r, g, b;
for (int k = 0; k < 256; k = k + 5) {
r = (k / 256.0) * red;
g = (k / 256.0) * green;
b = (k / 256.0) * blue;
setAll(r, g, b);
FastLED.show();
}
for (int k = 255; k >= 0; k = k - 5) {
r = (k / 256.0) * red;
g = (k / 256.0) * green;
b = (k / 256.0) * blue;
setAll(r, g, b);
FastLED.show();
}
}
void NewKITT(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
// LeftToRight(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
// RightToLeft(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
// OutsideToCenter(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
// CenterToOutside(red, green, blue, EyeSize, SpeedDelay, ReturnDelay);
}
void CenterToOutside(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for (int i = ((NUM_LEDS - EyeSize) / 2); i >= 0; i--) {
setAll(0, 0, 0);
setPixel(i, red / 10, green / 10, blue / 10);
for (int j = 1; j <= EyeSize; j++) {
setPixel(i + j, red, green, blue);
}
setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
setPixel(NUM_LEDS - i, red / 10, green / 10, blue / 10);
for (int j = 1; j <= EyeSize; j++) {
setPixel(NUM_LEDS - i - j, red, green, blue);
}
setPixel(NUM_LEDS - i - EyeSize - 1, red / 10, green / 10, blue / 10);
FastLED.show();
delay(SpeedDelay);
}
delay(ReturnDelay);
}
void OutsideToCenter(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for (int i = 0; i <= ((NUM_LEDS - EyeSize) / 2); i++) {
setAll(0, 0, 0);
setPixel(i, red / 10, green / 10, blue / 10);
for (int j = 1; j <= EyeSize; j++) {
setPixel(i + j, red, green, blue);
}
setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
setPixel(NUM_LEDS - i, red / 10, green / 10, blue / 10);
for (int j = 1; j <= EyeSize; j++) {
setPixel(NUM_LEDS - i - j, red, green, blue);
}
setPixel(NUM_LEDS - i - EyeSize - 1, red / 10, green / 10, blue / 10);
FastLED.show();
delay(SpeedDelay);
}
delay(ReturnDelay);
}
void LeftToRight(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for (int i = 0; i < NUM_LEDS - EyeSize - 2; i++) {
setAll(0, 0, 0);
setPixel(i, red / 10, green / 10, blue / 10);
for (int j = 1; j <= EyeSize; j++) {
setPixel(i + j, red, green, blue);
}
setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
FastLED.show();
delay(SpeedDelay);
}
delay(ReturnDelay);
}
void RightToLeft(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay) {
for (int i = NUM_LEDS - EyeSize - 2; i > 0; i--) {
setAll(0, 0, 0);
setPixel(i, red / 10, green / 10, blue / 10);
for (int j = 1; j <= EyeSize; j++) {
setPixel(i + j, red, green, blue);
}
setPixel(i + EyeSize + 1, red / 10, green / 10, blue / 10);
FastLED.show();
delay(SpeedDelay);
}
delay(ReturnDelay);
}
void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {
for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
for (int q = 0; q < 3; q++) {
for (int i = 0; i < NUM_LEDS; i = i + 3) {
setPixel(i + q, red, green, blue); //turn every third pixel on
}
FastLED.show();
delay(SpeedDelay);
for (int i = 0; i < NUM_LEDS; i = i + 3) {
setPixel(i + q, 0, 0, 0); //turn every third pixel off
}
}
}
}
void outsideinmeteors(){
int myVar=random(0,3);
switch (myVar) {
case 0:
red();
break;
case 1:
blue();
break;
case 2:
white();
}
}
void red(){
//static uint8_t hue;
for(int i = 0; i < NUM_LEDS/2; i++) {
// fade everything out
leds.fadeToBlackBy(20);
// let's set an led value
leds[i] = CRGB(250,0,0);
// now, let's first 20 leds to the top 20 leds,
leds(NUM_LEDS/2,NUM_LEDS-1) = leds(NUM_LEDS/2 - 1 ,0);
FastLED.delay(random (2,30));
}
}
void blue(){
//static uint8_t hue;
for(int i = 0; i < NUM_LEDS/2; i++) {
// fade everything out
leds.fadeToBlackBy(20);
// let's set an led value
leds[i] = CRGB(0,0,250);
// now, let's first 20 leds to the top 20 leds,
leds(NUM_LEDS/2,NUM_LEDS-1) = leds(NUM_LEDS/2 - 1 ,0);
FastLED.delay(random(2,30));
}
}
void white(){
//static uint8_t hue;
for(int i = 0; i < NUM_LEDS/2; i++) {
// fade everything out
leds.fadeToBlackBy(20);
// let's set an led value
leds[i] = CRGB(250,250,250);
// now, let's first 20 leds to the top 20 leds,
leds(NUM_LEDS/2,NUM_LEDS-1) = leds(NUM_LEDS/2 - 1 ,0);
FastLED.delay(random(2,30));
}
}