tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/apa102/main.go (about) 1 // Connects to an APA102 SPI RGB LED strip with 30 LEDS. 2 package main 3 4 import ( 5 "image/color" 6 "machine" 7 "time" 8 9 "tinygo.org/x/drivers/apa102" 10 ) 11 12 func main() { 13 machine.SPI0.Configure(machine.SPIConfig{ 14 Frequency: 500000, 15 Mode: 0}) 16 17 a := apa102.New(machine.SPI0) 18 leds := make([]color.RGBA, 30) 19 rg := false 20 21 for { 22 rg = !rg 23 for i := range leds { 24 rg = !rg 25 if rg { 26 leds[i] = color.RGBA{R: 0xff, G: 0x00, B: 0x00, A: 0x77} 27 } else { 28 leds[i] = color.RGBA{R: 0x00, G: 0xff, B: 0x00, A: 0x77} 29 } 30 } 31 32 a.WriteColors(leds) 33 time.Sleep(100 * time.Millisecond) 34 } 35 }