A competitive 1D racing game designed for microcontrollers using TinyGo, where players control cars racing along an LED strip using button inputs.
output.mp4
- 1D LED Strip Racing: Fast-paced racing action displayed on a single LED strip
- Stamina System: Strategic gameplay balancing speed vs. endurance
- Speed zones: Get a boost when driving slow through a speed zone
- Visual Feedback: Car colors fade to purple as stamina depletes
The game uses an energy-based physics system similar to OpenLED Race:
- Each button press adds energy to your car
- Velocity = √(energy)
- Natural friction causes deceleration over time
- Strategic pressing is more effective than button mashing
Players must balance speed with endurance:
- High Stamina: Car displays in full, bright color
- Medium Stamina: Car brightness dims proportionally
- Low Stamina: Car color fades toward purple, indicating exhaustion
- Recovery: Stamina regenerates slowly when not pressing buttons
Get a boost when driving through a zone marked by green LEDs
- Drive slow enough over the green LEDs to receive a boost
- Nothing happens if you're too fast
- The zone is spawned at a random position at the beginning
- The zone randomly changes the position during the game
This creates strategic depth where players must decide when to sprint and when to coast.
When no buttons are pressed for 30 seconds, the game enters demo mode:
- Cars race autonomously with simulated button presses
- Press any button to exit demo mode and start a new race
- TinyGo installed
- Compatible microcontroller
- LED strip driver library
# Build and flash
tinygo flash -target=nano-rp2040Adjust these constants in main.go for your setup:
const (
ledPin = machine.D2
ENERGY_INCREASE = 100
STAMINA_MIN = .1
STAMINA_START = 1.0
STAMINA_PRESS_LOSS = .1
STAMINA_CONSTANT_GAIN = .01
ENERGY_FACTOR = 25
FRICTION_DECAY_FACTOR = .95
MAX_BRIGHTNESS uint8 = 30
LAPS = 5
)Modify the player array in main.go
players: []Player{
{
car: NewCar(
"blue",
color.RGBA{
R: 0,
G: uint8(math.Round(0.49 * float64(MAX_BRIGHTNESS))),
B: MAX_BRIGHTNESS,
},
),
button: NewButton(machine.D7),
},
{
car: NewCar("red", color.RGBA{R: MAX_BRIGHTNESS, G: 0, B: 0}),
button: NewButton(machine.D8),
},
},- Heavily inspired by OpenLED Race
- Built with the excellent TinyGo project
- LED strip libraries and community examples