Created
December 28, 2024 14:44
-
-
Save eyeseast/9566cbeabd587654c7ea647706731217 to your computer and use it in GitHub Desktop.
Basic blinking lights on a neopixel ring with tinygo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connects to an WS2812 RGB LED strip with 10 LEDS. | |
// | |
// See either the others.go or digispark.go files in this directory | |
// for the neopixels pin assignments. | |
package main | |
import ( | |
"image/color" | |
"machine" | |
"time" | |
"tinygo.org/x/drivers/ws2812" | |
) | |
var ( | |
neo machine.Pin | |
leds [24]color.RGBA | |
) | |
func init() { | |
// Replace neo in the code below to match the pin | |
// that you are using if different. | |
neo = machine.GP2 | |
} | |
func main() { | |
neo.Configure(machine.PinConfig{Mode: machine.PinOutput}) | |
ws := ws2812.NewWS2812(neo) | |
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(500 * time.Millisecond) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment