Skip to content

ws2812: send full brightness as 0xff - #934

Merged
deadprogram merged 1 commit into
tinygo-org:devfrom
davecheney:ws2812-brightness
Oct 27, 2026
Merged

deadprogram merged 1 commit into
tinygo-org:devfrom
davecheney:ws2812-brightness

Conversation

@davecheney

@davecheney davecheney commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

applyBrightness scaled by brightness/256, so at the default brightness of 255 a 0xff color was sent as 0xfe. Scale by (brightness+1)/256 instead, and add tests for the arithmetic.

applyBrightness moves to its own file, and the files that import machine build only with TinyGo, so go test can run the tests. The package doc and go:generate lines move to doc.go, so go generate still works.

Checked on a Teensy 3.6 with a logic analyser: the colour bytes now decode as 0xff.

The trace shows one blue LED before and after the fix. Before, the last bit of the blue byte is a 0.

WS2812 data line on a Teensy 3.6 before and after the fix

applyBrightness scaled by brightness/256, so at the default brightness
of 255 a 0xff color was sent as 0xfe. Scale by (brightness+1)/256
instead, and add tests for the arithmetic.

applyBrightness moves to its own file, and the files that import
machine build only with TinyGo, so go test can run the tests. The
package doc and go:generate lines move to doc.go, so go generate still
works.

Checked on a Teensy 3.6 with a logic analyser: the colour bytes now
decode as 0xff.

@deadprogram deadprogram left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @davecheney thank you very much! Now merging.

@deadprogram
deadprogram merged commit 09a3540 into tinygo-org:dev Oct 27, 2026
1 check passed
@davecheney
davecheney deleted the ws2812-brightness branch October 27, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants