#include <Adafruit_NeoPixel.h>
#define LED_PIN 2
#define LED_WIDTH 11
#define LED_HEIGHT 22
#define BUTTON_PIN 8
Adafruit_NeoPixel strip(LED_WIDTH * LED_HEIGHT, LED_PIN, NEO_GRB + NEO_KHZ800);
// Define your custom image arrays here
byte image1[LED_HEIGHT][LED_WIDTH] = {
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0},
};
byte image2[LED_HEIGHT][LED_WIDTH] = {
{0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 1,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 1, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
};
byte currentImage = 0;
bool buttonPressed = false;
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
// Check if button is pressed
if (digitalRead(BUTTON_PIN) == LOW) {
if (!buttonPressed) { // if button was just pressed, switch to the next image and display it for 1 second
buttonPressed = true;
if (currentImage == 1) {
currentImage = 2;
} else if (currentImage == 2) {
currentImage = 3;
} else {
currentImage = 1;
}
displayImage(currentImage == 1 ? image1 : currentImage == 2 ? image2 : image3, 0, 255, 0);
delay(1000); // wait for 1 second
} else { // button is being held down
// Switch to the next image after 1 second and display it
static unsigned long lastImageSwitchTime = 0;
if (millis() - lastImageSwitchTime >= 1000) {
if (currentImage == 1) {
currentImage = 2;
} else if (currentImage == 2) {
currentImage = 3;
} else {
currentImage = 1;
}
displayImage(currentImage == 1 ? image1 : currentImage == 2 ? image2 : image3, 0, 255, 0);
lastImageSwitchTime = millis();
}
}
} else {
buttonPressed = false; // button is released, reset buttonPressed flag
// Display the current image and stop
displayImage(currentImage == 1 ? image1 : currentImage == 2 ? image2 : image3, 0, 255, 0);
}
}
void displayImage(byte image[][LED_WIDTH], byte red, byte green, byte blue) {
for (int y = 0; y < LED_HEIGHT; y++) {
if (y % 2 == 0) { // even rows
for (int x = 0; x < LED_WIDTH; x++) {
strip.setPixelColor(y * LED_WIDTH + x, image[y][x] * red, image[y][x] * green, image[y][x] * blue);
}
} else { // odd rows
for (int x = LED_WIDTH - 1; x >= 0; x--) {
strip.setPixelColor(y * LED_WIDTH + x, image[y][LED_WIDTH - 1 - x] * red, image[y][LED_WIDTH - 1 - x] * green, image[y][LED_WIDTH - 1 - x] * blue);
}
}
}
strip.show();
}