mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-25 00:48:59 +00:00
ws2812: switch to different color format
Use image/color.RGBA to represent RGB colors. This is more standard.
This commit is contained in:
+7
-6
@@ -2,6 +2,7 @@
|
|||||||
package ws2812
|
package ws2812
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image/color"
|
||||||
"machine"
|
"machine"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,12 +26,12 @@ func (d Device) Write(buf []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write the given color slice out using the WS2812 protocol.
|
// Write the given color slice out using the WS2812 protocol.
|
||||||
// Colors are specified in RGB format, and are send out in the common GRB
|
// Colors are sent out in the usual GRB format.
|
||||||
// format.
|
func (d Device) WriteColors(buf []color.RGBA) error {
|
||||||
func (d Device) WriteColors(buf []uint32) {
|
|
||||||
for _, color := range buf {
|
for _, color := range buf {
|
||||||
d.WriteByte(byte(color >> 8)) // green
|
d.WriteByte(color.G) // green
|
||||||
d.WriteByte(byte(color >> 16)) // red
|
d.WriteByte(color.R) // red
|
||||||
d.WriteByte(byte(color >> 0)) // blue
|
d.WriteByte(color.B) // blue
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user