#include <FastLED.h> // include the FastLED library code
#define DATA_PIN 2
#define NUM_LEDS 50
#define MAX_BRIGHTNESS 255
#define BRIGHTNESS 255 // To make the LED brighter set BRIGHTNESS to 255
#define LED_TYPE WS2811
CRGB leds[NUM_LEDS];
// runs once when program starts
void setup() {
Serial.begin(9600); //enables serial output for debugging
// initialize WS2811
FastLED.addLeds<LED_TYPE, DATA_PIN, RGB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
// declare the 4 arrays for the 7 top, 7 bottom, 7 left most, and 7 right most LEDs
int bottom_LEDS[7] = {42, 43, 44, 45, 46, 47, 48};
int top_LEDS[7] = {0, 1, 2, 3, 4, 5, 6};
int left_LEDS[7] = {0, 13, 14, 27, 28, 41, 42};
int right_LEDS[7] = {6, 7, 20, 21, 34, 35, 48};
//declare the 4 colors
CRGB colorRed = CRGB::Red;
CRGB colorGreen = CRGB::Green;
CRGB colorBlue = CRGB::Blue;
CRGB colorBlack = CRGB::Black;
void func1(int seq[], CRGB color1, CRGB color2, int dly){
for (int x=0; x < 7; x++){
leds[seq[x]] = color1;
leds[seq[x-1]] = color2;
FastLED.delay(dly);}
leds[seq[-1]] = color2;
}
void func2(int seq[], int from, int to, CRGB color1, CRGB color2, int dly){
for (int x= from ; x < to; x++){
leds[seq[x]] = color1;
leds[seq[x-1]] = color2;
FastLED.delay(dly);}
leds[seq[to]] = color2;
}
void func3(int seq[], int from, int to, CRGB color1, CRGB color2, int dly){
if (from > to){
for (int x= from ; x < to; x--){
leds[seq[x]] = color1;
leds[seq[x-1]] = color2;
FastLED.delay(dly);}
leds[seq[from]] = color2;
}
else {
for (int x= from ; x < to; x++){
leds[seq[x]] = color1;
leds[seq[x-1]] = color2;
FastLED.delay(dly);}
leds[seq[to]] = color2;
}
}
void loop() {
for (int x = 0; x < 7; x++){
leds[x] = colorRed;
leds[x-1] =colorBlack;
FastLED.delay(200);}
leds[6]=colorBlack;
// the loop to turn on each of the 7 LEDs on the TOP (GREEN)
// call func1() to light up the 7 LEDs on the TOP (GREEN)
func1(top_LEDS, colorRed, colorBlack, 200);
func2(right_LEDS, 0, 7, colorRed, colorBlack, 200);
func2(top_LEDS, 0, 7, colorGreen, colorBlack, 200);
func2(right_LEDS, 0, 7, colorGreen, colorBlack, 200);
func3(top_LEDS, 0, 7, colorBlue, colorBlack, 200);
func3(right_LEDS, 0, 7, colorBlue, colorBlack, 200);
func3(bottom_LEDS, 7, 0, colorBlue, colorBlack, 200);
func3(left_LEDS, 7, 0, colorBlue, colorBlack, 200);
}
// call func1() to light up the 7 LEDs on the RIGHT (GREEN)
// call func2() twice to light up the 13 LEDs on TOP & RIGHT without lighting up top right corner twice (RED)
// call func3() four times to light up all the LEDs on the edge one after the other (BLUE)
// call func4() four times (should behave exactly like the 4 func3() calls above) (GREEN)
// call func4() four times lighting up each of the four sides at the same time (GREEN)
// use func4() with dly=0 to light up all four sides in all 3 different colors (RED, BLUE, GREEN)
// use func4() to light up LEDs one at a time, but skipping the corners (GREEN)