Skip to content

ErfindergeistJuelichOfficial/tinygo-led-race

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TinyGo LED Race

A competitive 1D racing game designed for microcontrollers using TinyGo, where players control cars racing along an LED strip using button inputs.

output.mp4

Features

  • 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

Game Mechanics

Racing Physics

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

Stamina System

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

Speed zone

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.

Demo Mode

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

Installation

Prerequisites

  • TinyGo installed
  • Compatible microcontroller
  • LED strip driver library

Building and Flashing

# Build and flash
tinygo flash -target=nano-rp2040

Configuration

Adjust 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
)

Customization

Adding More Players

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),
    },
},

Acknowledgments

  • Heavily inspired by OpenLED Race
  • Built with the excellent TinyGo project
  • LED strip libraries and community examples

About

A competitive 1D racing game designed for microcontrollers using TinyGo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages