#include <FastLED.h>
#define LED_PIN 2
#define LED_COUNT 242
#define BUTTON_PIN 8
CRGB leds[LED_COUNT];
void fillInPattern(int patternIndex) {
// Fill in the array to draw your desired pattern
uint32_t one[11] = {
0x003FFE00, 0x007FFF80, 0x00FFFFFF, 0x00E007FF,
0x00C003FF, 0x00C003FF, 0x00C003FF, 0x00C003FF,
0x00C003FF, 0x00C003FF, 0x00C003FF
};
uint32_t two[22] = {
0x00007000, 0x0001C000, 0x00038000, 0x00070000,
0x00380070, 0x00300070, 0x00007000, 0x00007000,
0x0001C000, 0x0003E000, 0x0007F000, 0x000FE000,
0x003E0070, 0x003C00F0, 0x003800F0, 0x007000F8,
0x00700038, 0x00E00038, 0x00E0001C, 0x00C0001C,
0x00C0000C, 0x00C0000C
};
int ledIndex = 0;
for (int y = 0; y < 22; y++) {
if (y % 2 == 0) {
for (int x = 0; x < 11; x++) {
uint32_t mask = 0x80000000 >> x;
uint8_t pixel = (patternIndex == 0) ? ((one[y] & mask) != 0) : ((two[y] & mask) != 0);
leds[ledIndex] = pixel ? CRGB::Green : CRGB::Black;
ledIndex++;
}
} else {
for (int x = 10; x >= 0; x--) {
uint32_t mask = 0x80000000 >> x;
uint8_t pixel = (patternIndex == 0) ? ((one[y] & mask) != 0) : ((two[y] & mask) != 0);
leds[ledIndex] = pixel ? CRGB::Green : CRGB::Black;
ledIndex++;
}
}
}
}
void setup() {
FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, LED_COUNT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
static int patternIndex = 0;
static unsigned long patternStartTime = 0;
if (digitalRead(BUTTON_PIN) == LOW) { // Button is pressed
if (millis() - patternStartTime >= 1000) { // Time to switch to next pattern
patternIndex = (patternIndex + 1) % 2;
patternStartTime = millis();
fillInPattern(patternIndex);
FastLED.show();
}
} else { // Button is released
fillInPattern(patternIndex);
FastLED.show();
}
}