Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FASTLED_ESP8266_RAW_PIN_ORDER
- #define FASTLED_ESP8266_NODEMCU_PIN_ORDER
- #define FASTLED_ESP8266_D1_PIN_ORDER
- #include "FastLED.h"
- FASTLED_USING_NAMESPACE
- #define LED_LEAD D1
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- #define NUM_LEDS 175
- CRGB leds[NUM_LEDS];
- int BOTTOM_INDEX = 0;
- int TOP_INDEX = int(NUM_LEDS/2);
- int EVENODD = NUM_LEDS%2;
- int ledsX[NUM_LEDS][3]; //ARRAY FOR COPYING WHATS IN THE LED STRIP CURRENTLY (FOR CELL-AUTOMATA, MARCH, ECT)
- int thisdelay = 20;
- #define BRIGHTNESS 255
- #define FRAMES_PER_SECOND 120
- const int interval = 25;
- unsigned long previousMillis = millis();
- const int PIXEL_FLASH_INTERVAL = 25;
- //unsigned long previousMillis = millis();
- //FX LOOPS DELAY VAR
- int thisstep = 20;
- int thishue = 0;
- int thissat = 255;
- //LED FX VARS
- int idex = 0; //LED INDEX (0 TO NUM_LEDS-1)
- int ihue = 0; //HUE (0-255)
- int ibright = 0; //BRIGHTNESS (0-255)
- int isat = 0; //SATURATION (0-255);
- int bouncedirection = 0; //SWITCH FOR COLOR BOUNCE (0-1)
- float tcount = 0.0; //INC VAR FOR SIN LOOPS
- int lcount = 0; //ANOTHER COUNTING VAR
- /*
- //monitor button press
- bool buttonListener() {
- bool modeChanged = false;
- buttonState = digitalRead(BUTTON_LEAD);
- if (buttonState != lastButtonState) {
- if (buttonState == LOW) {
- mode++;
- modeChanged = true;
- delay(250); //Debounce delay
- }
- }
- lastButtonState = buttonState;
- return modeChanged;
- }
- */
- //---SET THE COLOR OF A SINGLE RGB LED
- void set_color_led(int adex, int cred, int cgrn, int cblu) {
- leds[adex].setRGB( cred, cgrn, cblu);
- }
- //---FIND INDEX OF HORIZONAL OPPOSITE LED
- int horizontal_index(int i) {
- //-ONLY WORKS WITH INDEX < TOPINDEX
- if (i == BOTTOM_INDEX) {return BOTTOM_INDEX;}
- if (i == TOP_INDEX && EVENODD == 1) {return TOP_INDEX + 1;}
- if (i == TOP_INDEX && EVENODD == 0) {return TOP_INDEX;}
- return NUM_LEDS - i;
- }
- //---FIND INDEX OF ANTIPODAL OPPOSITE LED
- int antipodal_index(int i) {
- int iN = i + TOP_INDEX;
- if (i >= TOP_INDEX) {iN = ( i + TOP_INDEX ) % NUM_LEDS; }
- return iN;
- }
- void copy_led_array(){
- for(int i = 0; i < NUM_LEDS; i++ ) {
- ledsX[i][0] = leds[i].r;
- ledsX[i][1] = leds[i].g;
- ledsX[i][2] = leds[i].b;
- }
- }
- void one_color_all(int cred, int cgrn, int cblu) { //-SET ALL LEDS TO ONE COLOR
- for(int i = 0 ; i < NUM_LEDS; i++ ) {
- leds[i].setRGB( cred, cgrn, cblu);
- }
- }
- /*
- void one_color_allHSV(int ahue) { //-SET ALL LEDS TO ONE COLOR (HSV)
- for(int i = 0 ; i < NUM_LEDS; i++ ) {
- leds[i] = CHSV(ahue, thissat, 255);
- }
- }
- */
- void rainbow_loop() { //-m3-LOOP HSV RAINBOW
- idex++;
- ihue = ihue + thisstep;
- if (idex >= NUM_LEDS) {idex = 0;}
- if (ihue > 255) {ihue = 0;}
- leds[idex] = CHSV(ihue, thissat, 255);
- LEDS.show();
- delay(thisdelay);
- }
- void random_burst() { //-m4-RANDOM INDEX/COLOR
- idex = random(0, NUM_LEDS);
- ihue = random(0, 255);
- leds[idex] = CHSV(ihue, thissat, 255);
- LEDS.show();
- delay(thisdelay);
- }
- void fade_vertical() { //-m12-FADE 'UP' THE LOOP
- idex++;
- if (idex > TOP_INDEX) {idex = 0;}
- int idexA = idex;
- int idexB = horizontal_index(idexA);
- ibright = ibright + 10;
- if (ibright > 255) {ibright = 0;}
- leds[idexA] = CHSV(thishue, thissat, ibright);
- leds[idexB] = CHSV(thishue, thissat, ibright);
- LEDS.show();
- delay(thisdelay);
- }
- void color_loop_vardelay() { //-m17-COLOR LOOP (SINGLE LED) w/ VARIABLE DELAY
- int di = abs(TOP_INDEX - idex);
- int t = constrain((10/di)*10, 10, 500);
- idex++;
- if (idex > NUM_LEDS) {idex = 0;}
- for(int i = 0; i < NUM_LEDS; i++ ) {
- if (i == idex) {
- leds[i] = CHSV(0, thissat, 255);
- }
- else {
- leds[i].r = 0; leds[i].g = 0; leds[i].b = 0;
- }
- }
- LEDS.show();
- delay(t);
- }
- void sin_bright_wave() { //-m19-BRIGHTNESS SINE WAVE
- for(int i = 0; i < NUM_LEDS; i++ ) {
- tcount = tcount + .1;
- if (tcount > 3.14) {tcount = 0.0;}
- ibright = int(sin(tcount)*255);
- leds[i] = CHSV(thishue, thissat, ibright);
- LEDS.show();
- delay(thisdelay);
- }
- }
- void pop_horizontal() { //-m20-POP FROM LEFT TO RIGHT UP THE RING
- int ix;
- if (bouncedirection == 0) {
- bouncedirection = 1;
- ix = idex;
- }
- else if (bouncedirection == 1) {
- bouncedirection = 0;
- ix = horizontal_index(idex);
- idex++;
- if (idex > TOP_INDEX) {idex = 0;}
- }
- for(int i = 0; i < NUM_LEDS; i++ ) {
- if (i == ix) {
- leds[i] = CHSV(thishue, thissat, 255);
- }
- else {
- leds[i].r = 0; leds[i].g = 0; leds[i].b = 0;
- }
- }
- LEDS.show();
- delay(thisdelay);
- }
- void rainbow_vertical() { //-m23-RAINBOW 'UP' THE LOOP
- idex++;
- if (idex > TOP_INDEX) {idex = 0;}
- ihue = ihue + thisstep;
- if (ihue > 255) {ihue = 0;}
- int idexA = idex;
- int idexB = horizontal_index(idexA);
- leds[idexA] = CHSV(ihue, thissat, 255);
- leds[idexB] = CHSV(ihue, thissat, 255);
- LEDS.show();
- delay(thisdelay);
- }
- void random_color_pop() { //-m25-RANDOM COLOR POP
- idex = random(0, NUM_LEDS);
- ihue = random(0, 255);
- one_color_all(0, 0, 0);
- leds[idex] = CHSV(ihue, thissat, 255);
- LEDS.show();
- delay(thisdelay);
- }
- void kitt() { //-m28-KNIGHT INDUSTIES 2000
- int rand = random(0, TOP_INDEX);
- for(int i = 0; i < rand; i++ ) {
- leds[TOP_INDEX+i] = CHSV(thishue, thissat, 255);
- leds[TOP_INDEX-i] = CHSV(thishue, thissat, 255);
- LEDS.show();
- //delay(thisdelay/rand);
- }
- for(int i = rand; i > 0; i-- ) {
- leds[TOP_INDEX+i] = CHSV(thishue, thissat, 0);
- leds[TOP_INDEX-i] = CHSV(thishue, thissat, 0);
- LEDS.show();
- delay(thisdelay/rand);
- }
- }
- void matrix() { //-m29-ONE LINE MATRIX
- int rand = random(0, 100);
- if (rand > 90) {
- leds[0] = CHSV(thishue, thissat, 255);
- }
- else {leds[0] = CHSV(thishue, thissat, 0);}
- copy_led_array();
- for(int i = 1; i < NUM_LEDS; i++ ) {
- leds[i].r = ledsX[i-1][0];
- leds[i].g = ledsX[i-1][1];
- leds[i].b = ledsX[i-1][2];
- }
- LEDS.show();
- delay(thisdelay);
- }
- void new_rainbow_loop(){ //-m88-RAINBOW FADE FROM FAST_SPI2
- ihue -= 1;
- fill_rainbow( leds, NUM_LEDS, ihue );
- LEDS.show();
- delay(thisdelay);
- }
- //----------------------------------------SETUP AND LOOP---------------------------------------------
- void setup() {
- FastLED.addLeds<LED_TYPE,LED_LEAD,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(BRIGHTNESS);
- }
- void loop() {
- int r = 10;
- thisdelay = 20; thisstep = 10; thishue = 0; thissat = 255;
- //one_color_all(255,255,255); LEDS.show(); delay(200);
- for(int i=0; i<r*20; i++) {rainbow_loop();}
- for(int i=0; i<r*20; i++) {random_burst();}
- thisdelay = 60; thishue = 180;
- for(int i = 0; i<r*5; i++) {fade_vertical();}
- thisdelay = 60; thishue = 95;
- for(int i=0; i<r*15; i++) {color_loop_vardelay();}
- thisdelay = 35; thishue = 180;
- for(int i=0; i<r; i++) {sin_bright_wave();}
- thisdelay = 100; thishue = 0;
- for(int i=0; i<r*5; i++) {pop_horizontal();}
- thisdelay = 50; thisstep = 15;
- for(int i=0; i<r*12; i++) {rainbow_vertical();}
- thisdelay = 35;
- for(int i=0; i<r*10; i++) {random_color_pop();}
- thisdelay = 100; thishue = 95;
- for(int i=0; i<r*10; i++) {kitt();}
- thisdelay = 30; thishue = 95;
- for(int i=0; i<r*25; i++) {matrix();}
- }
Advertisement
Add Comment
Please, Sign In to add comment