Skip to content

Instantly share code, notes, and snippets.

@gallaugher
Last active September 14, 2025 01:23
Show Gist options
  • Save gallaugher/be8eeef8befbdf459f59d663537cf4e4 to your computer and use it in GitHub Desktop.
Save gallaugher/be8eeef8befbdf459f59d663537cf4e4 to your computer and use it in GitHub Desktop.
Pixelblaze, Advance One Pixel at a Time
var holdMs = 120 // milliseconds each LED stays on (lower = faster)
var currentPixel = 0 // index of the currently lit pixel
var accumulatedMs = 0 // accumulated elapsed time (in milliseconds)
// A beforeRender fuction runs before each frame or refresh of all LEDs
export function beforeRender(delta) { // delta = ms since last frame (refresh of all LEDs)
accumulatedMs += delta // add this frame's time to the accumulator
// If we've held long enough, advance to the next pixel.
// NOTE: This advances at most one pixel per frame.
// For perfect catch-up on slow frames, replace `if` with a `while`.
if (accumulatedMs >= holdMs) {
accumulatedMs -= holdMs // keep leftover time for the next step
currentPixel = (currentPixel + 1) % pixelCount // wrap to 0 at the end
}
}
export function render(index) {
// Light only the current pixel. In Pixelblaze, (index == currentPixel)
// is a boolean that casts to 1 (true) or 0 (false), used here as V.
// Hue 0.02 ≈ orange-red, saturation 1 = pure color.
hsv(0.02, 1, index == currentPixel)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment