Files
drivers/examples/ws2812/main.go
T
2019-05-29 13:33:50 +02:00

40 lines
818 B
Go

// Connects to an WS2812 RGB LED strip with 10 LEDS, such as
// on an Adafruit Circuit Playground Express board.
//
// Replace machine.NEOPIXELS in the code below to match the pin
// that you are using, if you have a different board.
package main
import (
"image/color"
"machine"
"time"
"tinygo.org/x/drivers/ws2812"
)
func main() {
neo := machine.NEOPIXELS
neo.Configure(machine.PinConfig{Mode: machine.PinOutput})
ws := ws2812.New(neo)
leds := make([]color.RGBA, 10)
rg := false
for {
rg = !rg
for i := range leds {
rg = !rg
if rg {
// Alpha channel is not supported by WS2812 so we leave it out
leds[i] = color.RGBA{R: 0xff, G: 0x00, B: 0x00}
} else {
leds[i] = color.RGBA{R: 0x00, G: 0xff, B: 0x00}
}
}
ws.WriteColors(leds)
time.Sleep(100 * time.Millisecond)
}
}