tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/ws2812/main.go (about) 1 // Connects to an WS2812 RGB LED strip with 10 LEDS. 2 // 3 // See either the others.go or digispark.go files in this directory 4 // for the neopixels pin assignments. 5 package main 6 7 import ( 8 "image/color" 9 "machine" 10 "time" 11 12 "tinygo.org/x/drivers/ws2812" 13 ) 14 15 var ( 16 neo machine.Pin 17 leds [10]color.RGBA 18 ) 19 20 func main() { 21 neo.Configure(machine.PinConfig{Mode: machine.PinOutput}) 22 23 ws := ws2812.NewWS2812(neo) 24 rg := false 25 26 for { 27 rg = !rg 28 for i := range leds { 29 rg = !rg 30 if rg { 31 // Alpha channel is not supported by WS2812 so we leave it out 32 leds[i] = color.RGBA{R: 0xff, G: 0x00, B: 0x00} 33 } else { 34 leds[i] = color.RGBA{R: 0x00, G: 0xff, B: 0x00} 35 } 36 } 37 38 ws.WriteColors(leds[:]) 39 time.Sleep(100 * time.Millisecond) 40 } 41 }