forked from alexellis/blinkt_go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapa102.go
34 lines (31 loc) · 763 Bytes
/
apa102.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package blinkt
// High level functions common to all APA102 implementations
// WritePixels writes a sequence of pixels to the display.
//
// The pixels are prefixed with a start frame and terminated with the end frame.
func (a *APA102) WritePixels(pixels []pixel) {
// Start Frame
a.WriteFrame(0)
// LED frames
for _, p := range pixels {
a.WriteFrame(0xe0000000 | uint(p))
}
// End Frame
a.WriteFrame(0xffffffff)
}
// WriteFrame writes a single LED frame to the APA102.
//
// The frame value is passed as a 32bit uint and it clocked out MSB first.
func (a *APA102) WriteFrame(val uint) {
var mask = uint(0x80000000)
var bit int
for i := 0; i < 32; i++ {
if val&mask == 0 {
bit = 0
} else {
bit = 1
}
mask >>= 1
a.WriteBit(bit)
}
}