#include <FastLED.h>
#define DATA_PIN 2
#define NUM_LEDS 49
#define BRIGHTNESS 255
#define LED_TYPE WS2811
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(9600);
FastLED.addLeds<LED_TYPE, DATA_PIN, RGB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
void multiheart(int hue, int holdDelay, int fadeSpeed) {
int heart[35] = {
1, 2, 4, 5, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 29, 30, 31, 32, 33,
37, 38, 39, 45
};
for (int i = 0; i < 35; i++) {
leds[heart[i]] = CRGB::Black;
}
for (int v = 255; v >= 5; v -= fadeSpeed) {
for (int i = 0; i < 34; i++) {
leds[heart[i]] = CHSV(hue, 255, v);
}
FastLED.show();
FastLED.delay(fadeSpeed); // fadespeed
}
FastLED.delay(holdDelay); // delay before next color
}
void spiralRings(int hueOut, int hueIn, int delayTime, bool doCollapse) {
CHSV colorOut = CHSV(hueOut, 255, 255);
CHSV colorIn = CHSV(hueIn, 255, 255);
int ring0[] = {24};
int ring1[] = {16, 17, 18, 25, 32, 31, 30, 23};
int ring2[] = {8, 9, 10, 11, 12, 19, 26, 33, 40, 39, 38, 37, 36, 29, 22, 15};
int ring3[] = {0, 1, 2, 3, 4, 5, 6, 13, 20, 27, 34, 41,
48, 47, 46, 45, 44, 43, 42, 35, 28, 21, 14, 7
};
// array of rings (each a pointer to an array)
int* rings[] = {ring0, ring1, ring2, ring3};
// # of LED in each ring
int ringSizes[] = {1, 8, 16, 24}; // Manually define the number of LEDs in each ring
// expand out from center
for (int r = 0; r < 4; r++) {
for (int i = 0; i < ringSizes[r]; i++) {
leds[rings[r][i]] = colorOut;
}
FastLED.show();
delay(delayTime);
}
if (doCollapse) {
delay(300); // opt: pause before collapse
// collapse inward with second color
for (int r = 3; r >= 0; r--) {
for (int i = 0; i < ringSizes[r]; i++) {
leds[rings[r][i]] = colorIn;
}
FastLED.show();
delay(delayTime);
}
}
delay(400); // opt: pause before collpase
}
void moveSeq(int hue, int delayTime) {
CHSV color = CHSV(hue, 255, 255); // Set color for the movement
int positions[] = {0, 6, 48, 42};
int nextPositions[] = {6, 48, 42, 0}; // next position for each LED
int totalSteps = 7; // LED move 7 steps (including start and end)
for (int steps = 0; steps < totalSteps; steps++) {
for (int i = 0; i < 4; i++) {
// LED one step closer to next position
for (int j = positions[i]; j <= nextPositions[i]; j++) {
leds[j] = color;
FastLED.show();
delay(delayTime);
leds[j] = CRGB::Black;
}
}
// after lighting the LED -> move to next position
for (int i = 0; i < 4; i++) {
leds[positions[i]] = CRGB::Black;
positions[i] = nextPositions[i]; // the moving
}
FastLED.show();
}
FastLED.show();
}
void moveClockwise(int hue, int delayTime) {
CHSV color = CHSV(hue, 255, 255);
int path0[] = {0, 1, 2, 3, 4, 5, 6};
int path1[] = {6, 41, 20, 27, 34, 13, 48};
int path2[] = {48, 47, 46, 45, 44, 43, 42};
int path3[] = {42, 7, 28, 21, 14, 35, 0};
for (int step = 0; step < 7; step++) {
FastLED.clear();
leds[path0[step]] = color;
leds[path1[step]] = color;
leds[path2[step]] = color;
leds[path3[step]] = color;
FastLED.show();
delay(delayTime);
}
FastLED.show();
}
void moveClockwiseToCenter(int hue, int delayTime) {
CHSV color = CHSV(hue, 255, 255);
int path0[] = {0, 1, 2, 3, 4, 5, 6};
int path1[] = {6, 41, 20, 27, 34, 13, 48};
int path2[] = {48, 47, 46, 45, 44, 43, 42};
int path3[] = {42, 7, 28, 21, 14, 35, 0};
for (int step = 0; step < 7; step++) {
FastLED.clear();
leds[path0[step]] = color;
leds[path1[step]] = color;
leds[path2[step]] = color;
leds[path3[step]] = color;
FastLED.show();
delay(delayTime);
}
delay(300); // pause before converging to center
// path final position to center (24)
int toCenter0[] = {6, 12, 18, 24}; // from path0 end
int toCenter1[] = {48, 40, 32, 24}; // from path1 end
int toCenter2[] = {42, 36, 30, 24}; // from path2 end
int toCenter3[] = {0, 8, 16, 24}; // from path3 end
// converge to center
for (int step = 0; step < 4; step++) {
FastLED.clear();
leds[toCenter0[step]] = color;
leds[toCenter1[step]] = color;
leds[toCenter2[step]] = color;
leds[toCenter3[step]] = color;
FastLED.show();
delay(delayTime);
}
delay(500); // show center lit
FastLED.clear();
FastLED.show();
}
void moveEight(int hue, int delayTime) {
CHSV color = CHSV(hue, 255, 255);
int path0[] = {24, 23, 22, 21, 34, 35, 48, 47, 46, 45, 38, 31, 24};
int path1[] = {24, 25, 26, 27, 28, 41, 42, 43, 44, 45, 38, 31, 24};
for (int step = 0; step < 13; step++) {
FastLED.clear();
leds[path0[step]] = color;
leds[path1[step]] = color;
FastLED.show();
delay(delayTime);
}
// one function
int toCenter0[] = {17, 10, 3, 4, 5, 6, 7, 20, 21, 22, 23, 24}; // from path0 end
// converge to center
for (int step = 0; step < 12; step++) {
FastLED.clear();
leds[toCenter0[step]] = color;
FastLED.show();
delay(delayTime);
}
// 2nd function
int toCenter1[] = {25, 26, 27, 14, 13, 0, 1, 2, 3, 10, 17, 24}; // from path0 end
// converge to center
for (int step = 0; step < 12; step++) {
FastLED.clear();
leds[toCenter1[step]] = color;
FastLED.show();
delay(delayTime);
}
delay(500); // show center lit
FastLED.clear();
FastLED.show();
}
void prettySquare(int hue, int delayTime) {
CHSV color = CHSV(hue, 255, 255);
int path0[] = {24, 17, 10, 3};
int path1[] = {24, 31, 38, 45};
int path2[] = {24, 25, 26, 27};
int path3[] = {24, 23, 22, 21};
for (int step = 0; step < 4; step++) {
FastLED.clear();
leds[path0[step]] = color;
leds[path1[step]] = color;
leds[path2[step]] = color;
leds[path3[step]] = color;
FastLED.show();
delay(delayTime);
}
delay(500);
FastLED.clear();
FastLED.show();
}
void step(int num) {
for ( int x = 0; x < num; x=x+1 ){
leds[0] = CRGB::White;
FastLED.delay(300);
leds[0] = CRGB::Black;
FastLED.delay(300);
}
}
// Snake layout for the 7x7 grid (0 to 48)
int diagonalTopRightPaths[7][7] = {
{42}, // Step 0: {42}
{43, 41}, // Step 1: {43, 41}
{28, 40, 44}, // Step 2: {28, 40, 44}
{27, 29, 39, 45}, // Step 3: {27, 29, 39, 45}
{14, 26, 30, 38, 46}, // Step 4: {14, 26, 30, 38, 46}
{13, 15, 25, 31, 37, 47}, // Step 5: {13, 15, 25, 31, 37, 47}
{0, 12, 16, 24, 32, 36, 48} // Step 6: {0, 12, 16, 24, 32, 36, 48}
};
int diagonalBottomLeftPaths[7][7] = {
{6}, // Step 0: {6}
{5, 7}, // Step 1: {5, 7}
{4, 8, 20}, // Step 2: {4, 8, 20}
{3, 9, 19, 21}, // Step 3: {3, 9, 19, 21}
{2, 10, 18, 22, 34}, // Step 4: {2, 10, 18, 22, 34}
{1, 11, 17, 23, 33, 35}, // Step 5: {1, 11, 17, 23, 33, 35}
{0, 12, 16, 24, 32, 36, 48} // Step 6: {0, 12, 16, 24, 32, 36, 48}
};
// Function to animate both diagonals moving at the same time
void diagonalCrossingAnimation(int delayMs) {
int hue = 0;
for (int step = 0; step < 7; step++) {
// Clear previous LEDs
fill_solid(leds, NUM_LEDS, CRGB::Black);
// Light up LEDs for the current step in the bottom-left diagonal (formerly top-right)
for (int i = 0; i <= step; i++) {
leds[diagonalBottomLeftPaths[step][i]] = CHSV(hue % 256, 255, 255); // Rainbow effect for bottom-left diagonal
}
// Light up LEDs for the current step in the top-right diagonal (formerly bottom-left)
for (int i = 0; i <= step; i++) {
leds[diagonalTopRightPaths[step][i]] = CHSV((hue + 128) % 256, 255, 255); // Rainbow effect for top-right diagonal
}
FastLED.show();
hue += 32; // Increment hue for smooth rainbow effect
delay(delayMs); // Pause for smooth transition
}
}
void loop() {
step(3);
diagonalCrossingAnimation(150); // Speed of the animation (adjust as needed)
delay(1000); // Pause before repeating
//int ringHues[] = { 0, 64, 128, 192 }; // Red, Green, Blue, Purple
//circleAnimation(true, 150, ringHues); // Inward
//delay(500);
//circleAnimation(false, 150, ringHues); // Outward
//delay(1000);
//delay(500);
//multiheart(32, 1000, 20); // Orange (hue,holdDelay,fadeSpeed)
//multiheart(160, 950, 20); // Blue
//multiheart(96, 50, 40); // Green
//multiheart(210, 50, 40); // Purple
//multiheart(64, 25, 40); // Yellow
//multiheart(140, 50, 25); // Cyan
//spiralRings(96, 0, 100, true); // Green out, Red in, 100 delay, collapse
//delay(500);
//spiralRings(160, 96, 150, false); // Blue out, Green in, 150 delay, no collapse
// delay(500);
// spiralRings(140, 200, 100, true); // Green out, Red in, 100 delay, collapse
// delay(500);
// moveSeq(160, 100); // Blue, 100 delay (Transition)
// moveClockwise(160, 100); // Blue, 100 delay
//delay(1000);
//moveClockwise(96, 150); // Green, 150 delay
//delay(1000);
//moveClockwiseToCenter(160, 100); // Blue, 100 step delay
//delay(1000);
//moveEight(96, 100);
delay(1000);
//prettySquare(64, 150);
}