Skip to content

Instantly share code, notes, and snippets.

@mattetti
Created November 1, 2019 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattetti/0c398dad0c12ee4f2a7b61d6c2009d3e to your computer and use it in GitHub Desktop.
Save mattetti/0c398dad0c12ee4f2a7b61d6c2009d3e to your computer and use it in GitHub Desktop.
tinygo arduino nano 33 + apa102
// wiring: See https://github.com/tinygo-org/tinygo/blob/master/src/machine/board_arduino_nano33.go#L120
// MOSI / Data on port A3
// Clock on port A2
// power VUSB
// ground
package main
import (
"machine"
"time"
"image/color"
"tinygo.org/x/drivers/apa102"
)
func main() {
machine.SPI0.Configure(machine.SPIConfig{
Frequency: 500000,
Mode: 0})
a := apa102.New(machine.SPI0)
leds := make([]color.RGBA, 8)
rg := false
for {
rg = !rg
for i := range leds {
rg = !rg
if rg {
leds[i] = color.RGBA{R: 0xff, G: 0x00, B: 0x00, A: 0x77}
} else {
leds[i] = color.RGBA{R: 0x00, G: 0xff, B: 0x00, A: 0x77}
}
}
a.WriteColors(leds)
time.Sleep(100 * time.Millisecond)
}
}
// tinygo flash -target=arduino-nano33 -port=/dev/tty.usbmodem14301
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment