/
unicorn-blinky.go
45 lines (43 loc) · 1.04 KB
/
unicorn-blinky.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
35
36
37
38
39
40
41
42
43
44
45
package main
import "github.com/DrItanium/unicornhat"
import "time"
import "os"
import "os/signal"
import "syscall"
func terminate_unicorn(status int) {
for i := 0; i < 64; i++ {
unicornhat.SetPixelColor(uint(i), 0, 0, 0)
}
unicornhat.Show()
unicornhat.Shutdown(status)
}
func microsecond_delay(usec time.Duration) {
time.Sleep(usec * time.Microsecond)
}
func main() {
running := true
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT)
go func() {
<-signalChan
running = false
}()
unicornhat.SetBrightness(unicornhat.DefaultBrightness())
unicornhat.Init(64)
unicornhat.ClearLEDBuffer()
for running {
unicornhat.SetPixelColor(0, 1, 1, 1)
unicornhat.Show()
time.Sleep(10 * time.Microsecond)
for index := 1; index < 64; index++ {
unicornhat.SetPixelColor(uint(index-1), 0, 0, 0)
unicornhat.SetPixelColor(uint(index), 255, 255, 255)
unicornhat.Show()
microsecond_delay(10)
}
unicornhat.SetPixelColor(63, 0, 0, 0)
unicornhat.Show()
microsecond_delay(10)
}
defer terminate_unicorn(0)
}