Skip to content

Instantly share code, notes, and snippets.

@mattetti
Created November 1, 2019 06:19
Show Gist options
  • Select an option

  • Save mattetti/0c398dad0c12ee4f2a7b61d6c2009d3e to your computer and use it in GitHub Desktop.

Select an option

Save mattetti/0c398dad0c12ee4f2a7b61d6c2009d3e to your computer and use it in GitHub Desktop.

Revisions

  1. mattetti created this gist Nov 1, 2019.
    41 changes: 41 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    // 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