The Festival Begins
The great plaza of Cogsworth City buzzes with anticipation. Tonight is the Festival of Lights, the most celebrated evening in our clockwork metropolis. Citizens have spent weeks preparing their homes, their shops, their entire districts for this magical spectacle. The Mayor's proclamation echoes through the copper-lined streets: "Let every light tell a story, let every glow paint the night."
You stand at your workstation, three bright LEDs arranged before you like tiny suns waiting to be awakened. These aren't just lights, they're the heart of your contribution to the festival. The citizens below will look up at your window tonight, expecting wonder. They'll see dancing flames, gentle fairy glimmers, or steady beacon light, all controlled by the press of a single button.
Your HERO Board hums quietly, ready to orchestrate this symphony of light. The wires connect your vision to reality. Tonight, you're not just building a circuit, you're crafting an experience that will bring joy to thousands. The festival waits for no one, and the first stars are already appearing in the darkening sky above Cogsworth City's brass towers.
Three modes of illumination await your command: the wild flicker of festival fires, the gentle pulse of fairy lights, and the proud steady glow of celebration beacons. With each button press, you'll transform the character of your display, giving the people below a new reason to pause and smile. The Festival of Lights isn't just about technology, it's about creating moments of wonder in a world of gears and steam.
What You'll Learn
When you finish building your Festival of Lights display, you'll be able to:
- Create multiple lighting modes that switch with a button press
- Generate random flickering effects that mimic real flames
- Use mathematical functions to create smooth, breathing light patterns
- Control multiple LEDs independently with different brightness levels
- Implement button debouncing to prevent accidental mode changes
- Use timing functions to create effects without stopping your program
Understanding Light Modes
Think about the lighting in your own home. You have different modes for different moods: bright overhead lights for homework, dim lamps for relaxing, maybe even colored lights for parties. Each serves a purpose and creates a specific feeling.
Our Festival of Lights project works the same way, but with three distinct personalities. Fire mode creates the wild, unpredictable dance of flames using random numbers, just like how real fire never flickers the same way twice. Fairy mode uses smooth mathematical curves to create gentle breathing patterns, like fireflies pulsing in summer twilight. Steady mode provides reliable, constant illumination, like a lighthouse guiding ships safely to shore.
The magic happens in the switching mechanism. Instead of having three separate projects, we build one intelligent system that remembers which mode it's in and changes behavior accordingly. This is like having a universal remote that controls your TV, sound system, and lights all from one device.
The real power comes from timing control. Rather than using delays that freeze our entire program, we'll use a technique called "non-blocking timing" that lets us create smooth effects while still listening for button presses. This is like being able to walk and chew gum at the same time, essential for any interactive lighting display.
Wiring Your Festival Display

The button connects to digital pin 2 because it needs to detect quick press and release actions. Digital pins excel at reading clear HIGH and LOW signals, perfect for button detection.
Our three LEDs connect to PWM pins 9, 10, and 11. These special pins can output variable voltage levels, not just full ON or OFF. This capability lets us control brightness and create smooth fading effects that make our festival lights truly magical.
Each LED needs its own resistor to limit current flow. Without resistors, the LEDs would draw too much current and burn out instantly. Think of resistors as traffic cops, keeping the electrical flow at safe levels.
The onboard LED on pin 13 provides visual feedback when you press the button. This gives you immediate confirmation that your button press registered, essential for debugging and user experience.
Complete Festival Code
Here's the complete code for your Festival of Lights. Copy this into your IDE, then we'll walk through how each part works: