From 4c21e79d0e75ba53b5ed3754ad29d3bbc2ca21eb Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 22 Dec 2018 16:37:36 +0100 Subject: [PATCH] ws2812: switch to different color format Use image/color.RGBA to represent RGB colors. This is more standard. --- ws2812/ws2812.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ws2812/ws2812.go b/ws2812/ws2812.go index 8080fc2..010e924 100644 --- a/ws2812/ws2812.go +++ b/ws2812/ws2812.go @@ -2,6 +2,7 @@ package ws2812 import ( + "image/color" "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. -// Colors are specified in RGB format, and are send out in the common GRB -// format. -func (d Device) WriteColors(buf []uint32) { +// Colors are sent out in the usual GRB format. +func (d Device) WriteColors(buf []color.RGBA) error { for _, color := range buf { - d.WriteByte(byte(color >> 8)) // green - d.WriteByte(byte(color >> 16)) // red - d.WriteByte(byte(color >> 0)) // blue + d.WriteByte(color.G) // green + d.WriteByte(color.R) // red + d.WriteByte(color.B) // blue } + return nil }