//This sketch fades all LEDS in and out and changes colors after each cycle //This was used for the Christmas star Dec 2018 #include "FastLED.h" #define NUM_LEDS 50 //How many leds in your strip? #define DATA_PIN 5 //Arduino board pin used for led strip data CRGB leds[NUM_LEDS]; // Define the array of leds int howBright, clr; // Declare variables: howBright determines LED brightness, clr determines LED color bool up; //A bool(ean) variable can only be true or false void setup() { LEDS.addLeds(leds,NUM_LEDS); //Set up the LED string howBright=2; //Initialize the howBright variable fill_solid( leds, NUM_LEDS, CRGB:: DarkKhaki ); //Begin with all LEDs set to an off white color up = true; // When up is true, LEDs get brighter, otherwise they get dimmer clr=0; //Initialize the clr variable } void loop() { //This is the main program loop LEDS.setBrightness (howBright); //Set LED brightness value passed from the goUp and goDown subroutines FastLED.show(); //Show the LEDS delay (100); //Delay 100 msec (0.1 sec) if (up) { goUp(); } //If up varialbe is true, call the goUp subroutine else { goDown(); } //Otherwise, call the goDown subroutine } //====================== END void loop ================================= //This subroutine makes the LEDs get brighter void goUp() { howBright = howBright +1; if (howBright >= 36) { //Max brightness is 36, so if value is reached, change the value of the up variable up = !up; } } // This subroutine makes the LEDs get dimmer void goDown() { howBright = howBright - 1; if (howBright == 0) { //If brightness = zero, it's time to switch colors FastLED.clear(); //Turn all the LEDs off FastLED.show(); //Show the LEDS delay (300); if (clr==0){fill_solid(leds, NUM_LEDS, CRGB:: DarkKhaki );} //Choose the next color based on the else if (clr==1) {fill_solid(leds, NUM_LEDS, CRGB:: Blue );} //value of the clr variable else if (clr==2) {fill_solid(leds, NUM_LEDS, CRGB:: DarkGoldenrod );} else {fill_solid(leds, NUM_LEDS, CRGB:: Red );} up = !up; //Change value of the up variable clr=clr+1; //Increment the clr variable to change the color if (clr > 3){clr=0;} //If clr is > 3, go back to zero } }