Created
November 1, 2019 06:19
-
-
Save mattetti/0c398dad0c12ee4f2a7b61d6c2009d3e to your computer and use it in GitHub Desktop.
tinygo arduino nano 33 + apa102
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
// 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