WEEK 2: LED Strip Patterns
Hayool Park
WEEK 2: LED Strip Patterns
Hayool Park
What I wanted to learn, and why it interested me: I wanted to learn how to use an LED strip and code simple effects / patterns on it. Many of the project I will end up working on in my future design projects will include some form of lighting and I want to become familiar with the neccessary skills ahead of time.
Final outcome:
My final build is a 16-light LED bar made from two 8-pixel NeoPixel sticks chained end to end so they read as one continuous strip. Five buttons each trigger a different lighting pattern: a white strobe, a slow purple breathing fade, an amber fill that lights the LEDs one by one, a red dot that scans back and forth, and a scrolling rainbow. Pressing a button switches patterns instantly, and a potentiometer controls how fast the current pattern runs, from a slow drift to a rapid flicker.
Images of final creative/exploratory output
VIDEO: Shows the functioning patterns of the led bars and rate changing with the potentiometer
IMAGE: Shows 2 LED bars connected to a breadboard which contains 5 push buttons and a potentiometer as well, all wired up to an arduino uno.
Process and reflection:
First, I learned how to wire two NeoPixel sticks together so they act as one 16-LED strip, which taught me that data only flows one way, from DIN to DOUT. Then I learned how to program the strip in different ways: first setting colors, then turning all the lights on and off for flashing, and finally stepping through the LEDs to create motion like the one-by-one fill and the back-and-forth scanner. Next, I wired up five buttons and made each one switch to a different pattern. Finally, I added a potentiometer so the speed of every pattern could be adjusted live.
One interesting problem was that using delays made the buttons feel unresponsive, because the Arduino couldn't check them while it was waiting. I switched to a timer-based approach so the patterns keep running and the buttons respond instantly. I also learned to keep the brightness low so 16 LEDs could run safely off USB power. Along the way I made many small tweaks, like giving each pattern its own color, adjusting how fast each one runs relative to the knob, and smoothing out the breathing fade so it looked more natural.
Technical details
Electrical schematic of the game
/*
60-223 Intro to Physical Computing, fall 2026
Domain-specific Skill Building exercise: Five-Button Light Patterns
This sketch drives two chained 8-pixel NeoPixel sticks (16 LEDs total)
that sit end to end like one light bar. Five push buttons each pick a
lighting pattern: strobe, breathing, one-by-one fill, back-and-forth
scanner, and rainbow. A potentiometer sets how fast the pattern runs.
Brightness is capped so the LEDs can run safely off USB power.
AI was used in the coding of the led patterns.
Pin mapping:
Arduino pin | role | details
------------------------------------------------------------
A0 input momentary button, strobe
A1 input momentary button, breathing
A2 input momentary button, one-by-one fill
A3 input momentary button, scanner
A4 input momentary button, rainbow
A5 input potentiometer wiper, pattern speed
6 output NeoPixel data (through 470 ohm resistor)
Requires the "Adafruit NeoPixel" library (install from Library Manager).
Hayool Park, hayoolp@andrew.cmu.edu
*/
#include <Adafruit_NeoPixel.h>
const int LED_PIN = 6;
const int NUM_PIXELS = 16; // two sticks of 8, chained
const int POT_PIN = A5;
const int NUM_BUTTONS = 5;
const int BUTTON_PINS[NUM_BUTTONS] = {A0, A1, A2, A3, A4};
// how much slower each pattern steps compared to the base speed
const int SPEED_MULT[NUM_BUTTONS] = {4, 1, 3, 2, 1};
Adafruit_NeoPixel strip(NUM_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
int mode = 1; // start on breathing
unsigned long step = 0; // counts up each time the pattern advances
unsigned long lastStepTime = 0;
bool wasPressed[NUM_BUTTONS] = {false, false, false, false, false};
void setup() {
for (int i = 0; i < NUM_BUTTONS; i++) {
pinMode(BUTTON_PINS[i], INPUT_PULLUP); // button reads LOW when pressed
}
strip.begin();
strip.setBrightness(60); // about 25%, keeps current safe for USB
strip.show(); // start with all LEDs off
}
void loop() {
// buttons choose the pattern
for (int i = 0; i < NUM_BUTTONS; i++) {
bool pressed = (digitalRead(BUTTON_PINS[i]) == LOW);
if (pressed && !wasPressed[i]) { // the button was just pressed
mode = i;
step = 0; // restart the pattern from the beginning
}
wasPressed[i] = pressed;
}
// potentiometer sets the speed: turn it up = faster
int potValue = analogRead(POT_PIN);
unsigned long baseInterval = map(potValue, 0, 1023, 100, 2);
unsigned long interval = baseInterval * SPEED_MULT[mode];
// advance the pattern one step when enough time has passed
if (millis() - lastStepTime >= interval) {
lastStepTime = millis();
if (mode == 0) strobe();
else if (mode == 1) breathing();
else if (mode == 2) oneByOne();
else if (mode == 3) scanner();
else if (mode == 4) rainbow();
strip.show();
step++;
}
}
// all LEDs flash white on and off
void strobe() {
if (step % 2 == 0) {
strip.fill(strip.Color(255, 255, 255));
} else {
strip.clear();
}
}
// all LEDs fade up and down smoothly in purple
void breathing() {
int level = (step * 4) % 512; // counts 0 to 511
if (level > 255) level = 511 - level; // go up, then back down
level = strip.gamma8(level); // makes the fade look smoother
strip.fill(strip.Color(level, 0, level));
}
// LEDs turn on one at a time until all 16 are lit, then start over
void oneByOne() {
int count = step % (NUM_PIXELS + 1); // 0 to 16 LEDs lit
strip.clear();
for (int i = 0; i < count; i++) {
strip.setPixelColor(i, strip.Color(255, 80, 0)); // amber
}
}
// a red dot slides back and forth with a dim glow on each side
void scanner() {
int period = 2 * (NUM_PIXELS - 1); // one full trip there and back
int pos = step % period;
if (pos >= NUM_PIXELS) pos = period - pos; // bounce back
strip.clear();
strip.setPixelColor(pos, strip.Color(255, 0, 0));
if (pos > 0) strip.setPixelColor(pos - 1, strip.Color(40, 0, 0));
if (pos < NUM_PIXELS - 1) strip.setPixelColor(pos + 1, strip.Color(40, 0, 0));
}
// a rainbow spread across all 16 LEDs that scrolls along the bar
void rainbow() {
uint16_t firstHue = step * 256;
for (int i = 0; i < NUM_PIXELS; i++) {
uint16_t hue = firstHue + (i * 65536L / NUM_PIXELS);
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(hue)));
}
}