-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
102 lines (91 loc) · 2.23 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package main
import (
"strconv"
"time"
"github.com/kidoman/embd"
_ "github.com/kidoman/embd/host/rpi"
)
func main() {
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
for i := 9; i >= 0; i-- {
for gpioPin, isEnabled := range gpioLayoutFor(strconv.Itoa(i)) {
if err := embd.SetDirection(gpioPin, embd.Out); err != nil {
panic(err)
}
if isEnabled == 1 {
if err := embd.DigitalWrite(gpioPin, embd.High); err != nil {
panic(err)
}
} else {
if err := embd.DigitalWrite(gpioPin, embd.Low); err != nil {
panic(err)
}
}
}
time.Sleep(1 * time.Second)
}
}
func gpioLayoutFor(letter string) map[int]int {
var resultingGpio = make(map[int]int)
for index, element := range segmentPinLayoutFor(letter) {
resultingGpio[gpioForSegmentPosition(index)] = element
}
return resultingGpio
}
func gpioForSegmentPosition(position int) int {
return map[int]int{
0: 12,
1: 16,
2: 26,
3: 25,
4: 24,
5: 23,
6: 18,
}[position]
}
func segmentPinLayoutFor(letter string) []int {
return map[string][]int{
"0": {1, 1, 1, 1, 1, 1, 0},
"1": {0, 1, 1, 0, 0, 0, 0},
"2": {1, 1, 0, 1, 1, 0, 1},
"3": {1, 1, 1, 1, 0, 0, 1},
"4": {0, 1, 1, 0, 0, 1, 1},
"5": {1, 0, 1, 1, 0, 1, 1},
"6": {1, 0, 1, 1, 1, 1, 1},
"7": {1, 1, 1, 0, 0, 0, 0},
"8": {1, 1, 1, 1, 1, 1, 1},
"9": {1, 1, 1, 1, 0, 1, 1},
" ": {0, 0, 0, 0, 0, 0, 0},
"_": {0, 0, 0, 1, 0, 0, 0},
"-": {0, 0, 0, 0, 0, 0, 1},
"A": {1, 1, 1, 0, 1, 1, 1},
"B": {0, 0, 1, 1, 1, 1, 1},
"C": {0, 0, 0, 1, 1, 0, 1},
"D": {0, 1, 1, 1, 1, 0, 1},
"E": {1, 0, 0, 1, 1, 1, 1},
"F": {1, 0, 0, 0, 1, 1, 1},
"G": {1, 0, 1, 1, 1, 1, 0},
"H": {0, 0, 1, 0, 1, 1, 1},
"I": {0, 0, 1, 0, 0, 0, 0},
"J": {0, 1, 1, 1, 1, 0, 0},
"K": {1, 0, 1, 0, 1, 1, 1},
"L": {0, 0, 0, 1, 1, 1, 0},
"M": {1, 1, 1, 0, 1, 1, 0},
"N": {0, 0, 1, 0, 1, 0, 1},
"O": {0, 0, 1, 1, 1, 0, 1},
"P": {1, 1, 0, 0, 1, 1, 1},
"Q": {1, 1, 1, 0, 0, 1, 1},
"R": {0, 0, 0, 0, 1, 0, 1},
"S": {0, 0, 1, 1, 0, 1, 1},
"T": {0, 0, 0, 1, 1, 1, 1},
"U": {0, 0, 1, 1, 1, 0, 0},
"V": {0, 1, 1, 1, 1, 1, 0},
"W": {0, 1, 1, 1, 1, 1, 1},
"X": {0, 1, 1, 0, 1, 1, 1},
"Y": {0, 1, 1, 1, 0, 1, 1},
"Z": {1, 1, 0, 1, 1, 0, 0},
}[letter]
}