#include <Arduino.h>
#include <FastLED.h>
#define RUNS 30
#define NUM_LEDS 2160
#define NUM_LEDS_PER_STRIP 72
#define NUM_LEDS_PER_SEGMENT 360
// Define the data pins for the LED strips
#define DP_1 7
#define DP_2 8
#define DP_3 9
#define DP_4 10
#define DP_5 11
#define DP_6 12
// Define the LED strip type
#define LED_TYPE WS2812B
// Define the color order of the LED strip
#define COLOR_ORDER GRB
CRGB leds1[NUM_LEDS_PER_SEGMENT];
CRGB leds2[NUM_LEDS_PER_SEGMENT];
CRGB leds3[NUM_LEDS_PER_SEGMENT];
CRGB leds4[NUM_LEDS_PER_SEGMENT];
CRGB leds5[NUM_LEDS_PER_SEGMENT];
CRGB leds6[NUM_LEDS_PER_SEGMENT];
const bool DEBUG_MODE = false;
const int switchPins[] = {6, 5, 4, 3, 2}; // Pins connected to the switches
int pattern = 0;
void setup()
{
if (DEBUG_MODE)
{
Serial.begin(9600);
}
// Initialize the LED strip
FastLED.addLeds<LED_TYPE, DP_1, COLOR_ORDER>(leds1, NUM_LEDS_PER_SEGMENT);
FastLED.addLeds<LED_TYPE, DP_2, COLOR_ORDER>(leds2, NUM_LEDS_PER_SEGMENT);
FastLED.addLeds<LED_TYPE, DP_3, COLOR_ORDER>(leds3, NUM_LEDS_PER_SEGMENT);
FastLED.addLeds<LED_TYPE, DP_4, COLOR_ORDER>(leds4, NUM_LEDS_PER_SEGMENT);
FastLED.addLeds<LED_TYPE, DP_5, COLOR_ORDER>(leds5, NUM_LEDS_PER_SEGMENT);
FastLED.addLeds<LED_TYPE, DP_6, COLOR_ORDER>(leds6, NUM_LEDS_PER_SEGMENT);
FastLED.setMaxRefreshRate(0);
FastLED.clear();
// Initialize switch pins as inputs
for (int i = 0; i < 5; i++)
{
pinMode(switchPins[i], INPUT_PULLUP); // Enable internal pull-up resistors
}
}
// Animate a chase effect with a rainbow pattern.
void rainbowChase()
{
static uint8_t startIndex = 0;
startIndex += 24; /* motion speed */
// Iterate all LEDs to create a rainbow chase effect, do the different pins in parralel.
for (int i = 0; i < NUM_LEDS_PER_SEGMENT; i++)
{
leds1[i] = CHSV((startIndex + (i * 2)), 255, 255);
leds2[i] = CHSV((startIndex + (i * 2)), 255, 255);
leds3[i] = CHSV((startIndex + (i * 2)), 255, 255);
leds4[i] = CHSV((startIndex + (i * 2)), 255, 255);
leds5[i] = CHSV((startIndex + (i * 2)), 255, 255);
leds6[i] = CHSV((startIndex + (i * 2)), 255, 255);
}
FastLED.show();
// delay(1); /* frame rate */
}
// Randomise LEDS flying from edge to edge in multiple ares, with a trail behind.
// Optinally pass in a colour value. If left blank, colour will be randomised.
void multipleTrails(CRGB trailColor = CRGB::Black)
{
static int tailLength = 10; // Adjust the length of the tail
static int shootingSpeed = 50; // Adjust the speed of the shooting effect
static unsigned long lastUpdateTime = 0;
static int currentPosition = 0;
// Update the shooting effect
if (millis() - lastUpdateTime >= shootingSpeed)
{
// Move the shooting LED position
currentPosition += 8;
// If LED reaches the end, reset to start
if (currentPosition >= NUM_LEDS_PER_SEGMENT)
{
currentPosition = 0;
}
CRGB tc = trailColor != CRGB::Black ? trailColor : CHSV(random(255), 255, 255);
// Turn off the previous tail LEDs
for (int i = 1; i <= tailLength; i++)
{
int tailPosition = currentPosition - i;
if (tailPosition >= 0)
{
for (int segment = 0; segment < RUNS; segment++)
{
switch (segment)
{
case 0:
leds1[tailPosition] = tc;
break;
case 1:
leds2[tailPosition] = tc;
break;
case 2:
leds3[tailPosition] = tc;
break;
case 3:
leds4[tailPosition] = tc;
break;
case 4:
leds5[tailPosition] = tc;
break;
default:
break;
}
}
}
}
// Turn on the shooting LED
for (int segment = 0; segment < RUNS; segment++)
{
switch (segment)
{
case 0:
leds1[currentPosition] = CRGB::White;
break;
case 1:
leds2[currentPosition] = CRGB::White;
break;
case 2:
leds3[currentPosition] = CRGB::White;
break;
case 3:
leds4[currentPosition] = CRGB::White;
break;
case 4:
leds5[currentPosition] = CRGB::White;
break;
default:
break;
}
}
// Show the updated LEDs
FastLED.show();
lastUpdateTime = millis();
}
}
void rgbypwSegments()
{
// Iterate all segments and light up the LEDs with different colours.
for (int i = 0; i < NUM_LEDS_PER_SEGMENT; i++)
{
leds1[i] = CRGB::Red;
leds2[i] = CRGB::Green;
leds3[i] = CRGB::Blue;
leds4[i] = CRGB::Yellow;
leds5[i] = CRGB::Purple;
leds6[i] = CRGB::White;
}
FastLED.show();
}
CRGB nextTriColour(const CRGB currentColour)
{
return (currentColour == CRGB::Green) ? CRGB::White : (currentColour == CRGB::White) ? CRGB::Orange : CRGB::Green;
}
// Animate a chase effect upwards on the pentagons
void triColourUp()
{
// Set up initial colours
for (int i = 0; i < NUM_LEDS_PER_SEGMENT; i++)
{
leds1[i] = CRGB::Green;
if (i < (NUM_LEDS_PER_SEGMENT / 5))
{
leds2[i] = CRGB::Green;
leds3[i] = leds4[i] = leds5[i] = CRGB::White;
leds6[i] = CRGB::Orange;
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 2)
{
leds2[i] = leds4[i] = leds6[i] = CRGB::White;
leds3[i] = CRGB::Green;
leds5[i] = CRGB::Orange;
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 3)
{
leds2[i] = leds3[i] = leds5[i] = CRGB::White;
leds4[i] = CRGB::Green;
leds6[i] = CRGB::Orange;
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 4)
{
leds2[i] = CRGB::Green;
leds3[i] = leds4[i] = leds6[i] = CRGB::White;
leds5[i] = CRGB::Orange;
}
else
{
leds2[i] = leds4[i] = leds5[i] = CRGB::White;
leds3[i] = CRGB::Green;
leds6[i] = CRGB::Orange;
}
}
FastLED.show();
delay(1000);
for (int i = 0; i < NUM_LEDS_PER_SEGMENT; i++)
{
leds1[i] = nextTriColour(leds1[i]);
leds2[i] = nextTriColour(leds2[i]);
leds3[i] = nextTriColour(leds3[i]);
leds4[i] = nextTriColour(leds4[i]);
leds5[i] = nextTriColour(leds5[i]);
leds6[i] = nextTriColour(leds6[i]);
}
FastLED.show();
delay(1000);
for (int i = 0; i < NUM_LEDS_PER_SEGMENT; i++)
{
leds1[i] = nextTriColour(leds1[i]);
leds2[i] = nextTriColour(leds2[i]);
leds3[i] = nextTriColour(leds3[i]);
leds4[i] = nextTriColour(leds4[i]);
leds5[i] = nextTriColour(leds5[i]);
leds6[i] = nextTriColour(leds6[i]);
}
FastLED.show();
delay(1000); /* frame rate */
}
// Animate a chase effect upwards on the vertical lines
void lightVerticals()
{
// Set up initial colours
for (int i = 0; i < NUM_LEDS_PER_SEGMENT; i++)
{
if (i < (NUM_LEDS_PER_SEGMENT / 5))
{
leds2[i] = CRGB::Red; //forwards
leds5[i] = CRGB::Indigo; //forwards
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 2)
{
leds3[i] = CRGB::Yellow; //backwards
leds6[i] = CRGB::Gold; //backwards
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 3)
{
leds4[i] = CRGB::Blue; //backwards
leds5[i] = CRGB::Violet; //backwards
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 4)
{
leds2[i] = CRGB::Orange; //backwards
leds6[i] = CRGB::White; //backwards
}
else
{
leds3[i] = CRGB::Green; //backwards
leds5[i] = CRGB::Silver; //backwards
}
}
FastLED.show();
}
void waveVerticals()
{
// Loop through each LED in the segment
for (int i = 0; i < NUM_LEDS_PER_SEGMENT; i++)
{
// Calculate brightness using a sine wave
uint8_t brightness = 255 * (0.5 + 0.5 * sin(2 * PI * (millis() / 1000.0) + i * PI / NUM_LEDS_PER_SEGMENT));
// Set colors based on segment position
if (i < (NUM_LEDS_PER_SEGMENT / 5))
{
leds2[i] = CRGB(brightness, 0, 0); // Red wave
leds5[i] = CRGB(brightness, 0, 255); // Indigo wave
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 2)
{
leds3[i] = CRGB(brightness, brightness, 0); // Yellow wave
leds6[i] = CRGB(brightness, 215, 0); // Gold wave
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 3)
{
leds4[i] = CRGB(0, 0, brightness); // Blue wave
leds5[i] = CRGB(brightness, 0, brightness); // Violet wave
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 4)
{
leds2[i] = CRGB(brightness, 100, 0); // Orange wave
leds6[i] = CRGB(brightness, brightness, brightness); // White wave
}
else
{
leds3[i] = CRGB(0, brightness, 0); // Green wave
leds5[i] = CRGB(brightness, brightness, brightness); // Silver wave
}
}
FastLED.show();
}
void waveRandomColourVerticals()
{
// Loop through each LED in the segment
for (int i = 0; i < NUM_LEDS_PER_SEGMENT; i++)
{
// Calculate brightness using a sine wave
uint8_t brightness = 255 * (0.5 + 0.5 * sin(2 * PI * (millis() / 1000.0) + i * PI / NUM_LEDS_PER_SEGMENT));
// Set colors based on segment position
if (i < (NUM_LEDS_PER_SEGMENT / 5))
{
// First segment: wave moves from start to end
leds2[i] = CRGB(random(256), random(256), random(256)); // Random color
leds5[i] = CRGB(random(256), random(256), random(256)); // Random color
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 2)
{
// Second segment
leds3[i] = CRGB(random(256), random(256), random(256)); // Random color
leds6[i] = CRGB(random(256), random(256), random(256)); // Random color
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 3)
{
// Third segment
leds4[i] = CRGB(random(256), random(256), random(256)); // Random color
leds5[i] = CRGB(random(256), random(256), random(256)); // Random color
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 4)
{
// Fourth segment
leds2[i] = CRGB(random(256), random(256), random(256)); // Random color
leds6[i] = CRGB(random(256), random(256), random(256)); // Random color
}
else
{
// Fifth segment
leds3[i] = CRGB(random(256), random(256), random(256)); // Random color
leds5[i] = CRGB(random(256), random(256), random(256)); // Random color
}
}
FastLED.show();
}
void waveVerticalsUpwards()
{
// Loop through each LED in the segment
for (int i = 0; i < NUM_LEDS_PER_SEGMENT; i++)
{
// Calculate brightness using a sine wave
uint8_t brightness = 255 * (0.5 + 0.5 * sin(2 * PI * (millis() / 1000.0) + i * PI / NUM_LEDS_PER_SEGMENT));
// Set colors based on segment position
if (i < (NUM_LEDS_PER_SEGMENT / 5))
{
leds2[i] = CRGB(brightness, 0, 0); // Red wave
leds5[i] = CRGB(brightness, 0, 255); // Indigo wave
}
}
for (int i = NUM_LEDS_PER_SEGMENT -1; i >=(NUM_LEDS_PER_SEGMENT / 5); i--){
uint8_t brightness = 255 * (0.5 + 0.5 * sin(2 * PI * (millis() / 1000.0) + i * PI / NUM_LEDS_PER_SEGMENT));
if (i < (NUM_LEDS_PER_SEGMENT / 5) * 2 && i >= (NUM_LEDS_PER_SEGMENT / 5))
{
leds3[i] = CRGB(brightness, brightness, 0); // Yellow wave
leds6[i] = CRGB(brightness, 215, 0); // Gold wave
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 3 && i >= (NUM_LEDS_PER_SEGMENT / 5) * 2)
{
leds4[i] = CRGB(0, 0, brightness); // Blue wave
leds5[i] = CRGB(brightness, 0, brightness); // Violet wave
}
else if (i < (NUM_LEDS_PER_SEGMENT / 5) * 4 && i >= (NUM_LEDS_PER_SEGMENT / 5) * 3)
{
leds2[i] = CRGB(brightness, 100, 0); // Orange wave
leds6[i] = CRGB(brightness, brightness, brightness); // White wave
}
else
{
leds3[i] = CRGB(0, brightness, 0); // Green wave
leds5[i] = CRGB(brightness, brightness, brightness); // Silver wave
}
}
FastLED.show();
}
void loop()
{
FastLED.show();
selectPattern();
}
void selectPattern()
{
// Read the state of each switch and calculate the binary value
int binaryValue = 0;
for (int i = 0; i < 5; i++)
{
binaryValue |= digitalRead(switchPins[i]) << i;
}
// Convert binary value to decimal mode
pattern = binaryValue;
// Print the mode value to the Serial Monitor
if (DEBUG_MODE)
{
Serial.print("Mode: ");
Serial.print(pattern);
Serial.print(" (Binary: ");
Serial.print(pattern, BIN);
Serial.println(")");
}
FastLED.clear();
switch (pattern)
{
case 0:
rainbowChase();
break;
case 1:
multipleTrails();
break;
case 2:
multipleTrails(CRGB::Red);
break;
case 3:
multipleTrails(CRGB::Green);
break;
case 4:
multipleTrails(CRGB::Blue);
break;
case 5:
rgbypwSegments();
break;
case 6:
// triColourUp();
// lightVerticals();
// waveVerticals();
waveVerticalsUpwards();
// waveRandomColourVerticals();
break;
// Add the rest of the case n..31 as needed.
default:
break;
}
}