Skip to content

Commit fa29657

Browse files
davecheneydeadprogram
authored andcommitted
examples/apa102: add red Cylon sweep example for Blinkt!
1 parent 6c62ea9 commit fa29657

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

  • examples/apa102/blinkt-cylon
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Draws a red Cylon sweep on a Pimoroni Blinkt! connected to the 40 pin
2+
// header of a Waveshare RP2040-PiZero.
3+
// https://shop.pimoroni.com/products/blinkt
4+
package main
5+
6+
import (
7+
"image/color"
8+
"machine"
9+
"time"
10+
11+
"tinygo.org/x/drivers/apa102"
12+
)
13+
14+
const numLEDs = 8
15+
16+
func main() {
17+
// Blinkt! uses BCM23 for data and BCM24 for clock. These are not
18+
// hardware SPI pins on the RP2040, so use software SPI.
19+
leds := apa102.NewSoftwareSPI(machine.GP24, machine.GP23, 1)
20+
21+
var c [numLEDs]color.RGBA
22+
pos, dir := 0, 1
23+
for {
24+
for i := range c {
25+
c[i].R /= 4
26+
c[i].A = 0x20
27+
}
28+
c[pos].R = 0xff
29+
leds.WriteColors(c[:])
30+
31+
if pos+dir < 0 || pos+dir >= numLEDs {
32+
dir = -dir
33+
}
34+
pos += dir
35+
time.Sleep(80 * time.Millisecond)
36+
}
37+
}

0 commit comments

Comments
 (0)