/*
Prototype 0 Goals = Light LEDs individually + Control LED color + Control LED lighting direction.
✅ lightUpColor1() → Lights LEDs in a zigzag pattern (left-to-right, then right-to-left).
✅ lightUpColor2() → Lights LEDs strictly left-to-right for both rows in one color.
✅ lightUpColor3() → Lights LEDs strictly left-to-right, but with alternating RGB
*/
#include <Adafruit_NeoPixel.h>
#define LED_PIN 2 // Pin connected to the data input of the LED strip
#define NUM_LEDS 40 // 2 rows * 20 columns
#define COLUMNS 20 // Number of columns in the matrix
#define ROWS 2 // Number of rows in the matrix
// Create a NeoPixel object to control the LED strip
// NUM_LEDS: Number of LEDs in the strip (40 for 2x20 matrix)
// LED_PIN: Pin where the LED data line is connected (D2 in this case)
// NEO_GRB: Specifies the color order (Green, Red, Blue) used by WS2812B LEDs
// NEO_KHZ800: Defines the signal timing (800kHz), which is standard for WS2812B
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
lightUpColor1(255, 0, 0); // Red
lightUpColor1(0, 255, 0); // Green
lightUpColor1(0, 0, 255); // Blue
lightUpColor2(255, 0, 0); // Red
lightUpColor2(0, 255, 0); // Green
lightUpColor2(0, 0, 255); // Blue
lightUpColor3(); // Strict left-to-right pattern - Alternating RGB
}
// Function to light up each LED in sequence with a given color
void lightUpColor1(uint8_t r, uint8_t g, uint8_t b) {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, strip.Color(r, g, b)); // Set color
strip.show(); // Update strip
delay(100); // Delay to make the effect visible
}
delay(500); // Pause before switching to the next color
strip.clear();
strip.show();
}
// Function to light up LEDs strictly left to right in both rows
void lightUpColor2(uint8_t r, uint8_t g, uint8_t b) {
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLUMNS; col++) {
int index;
if (row % 2 == 0) {
// Even rows (row 0): Normal left-to-right
index = row * COLUMNS + col;
} else {
// Odd rows (row 1): Reverse mapping to force left-to-right
index = (row + 1) * COLUMNS - (col + 1);
}
strip.setPixelColor(index, strip.Color(r, g, b));
strip.show();
delay(100);
}
}
delay(500);
strip.clear();
strip.show();
}
// Function to light up LEDs strictly left to right but alternating colors (RGBRGB)
void lightUpColor3() {
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLUMNS; col++) {
int index;
if (row % 2 == 0) {
index = row * COLUMNS + col;
} else {
index = (row + 1) * COLUMNS - (col + 1);
}
// Alternate colors R -> G -> B
uint8_t r = (index % 3 == 0) ? 255 : 0;
uint8_t g = (index % 3 == 1) ? 255 : 0;
uint8_t b = (index % 3 == 2) ? 255 : 0;
strip.setPixelColor(index, strip.Color(r, g, b));
strip.show();
delay(100);
}
}
delay(500);
strip.clear();
strip.show();
}