-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
88 lines (75 loc) · 1.54 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
package main
import (
"machine"
"machine/usb/hid/keyboard"
"time"
)
var (
c1 = machine.D8
c2 = machine.D9
c3 = machine.D10
r1 = machine.D1
r2 = machine.D2
)
func main() {
kb := keyboard.Port()
c1.Configure(machine.PinConfig{Mode: machine.PinOutput})
c2.Configure(machine.PinConfig{Mode: machine.PinOutput})
c3.Configure(machine.PinConfig{Mode: machine.PinOutput})
r1.Configure(machine.PinConfig{Mode: machine.PinInputPulldown})
r2.Configure(machine.PinConfig{Mode: machine.PinInputPulldown})
for {
// SW1 / SW2 を読み込むため、 c1 を H、 c2 と c3 を L に
c1.High()
c2.Low()
c3.Low()
time.Sleep(1 * time.Millisecond) // 少し待つ
// SW1
if r1.Get() {
kb.Down(keyboard.KeyA)
} else {
kb.Up(keyboard.KeyA)
}
// SW2
if r2.Get() {
kb.Down(keyboard.KeyB)
} else {
kb.Up(keyboard.KeyB)
}
// SW3 / SW4 を読み込むため、 c2 を H、 c1 と c3 を L に
c1.Low()
c2.High()
c3.Low()
time.Sleep(1 * time.Millisecond) // 少し待つ
// SW3
if r1.Get() {
kb.Down(keyboard.KeyC)
} else {
kb.Up(keyboard.KeyC)
}
// SW4
if r2.Get() {
kb.Down(keyboard.KeyD)
} else {
kb.Up(keyboard.KeyD)
}
// SW5 / SW6 を読み込むため、 c3 を H、 c1 と c2 を L に
c1.Low()
c2.Low()
c3.High()
time.Sleep(1 * time.Millisecond) // 少し待つ
// SW5
if r1.Get() {
kb.Down(keyboard.KeyE)
} else {
kb.Up(keyboard.KeyE)
}
// SW6
if r2.Get() {
kb.Down(keyboard.KeyF)
} else {
kb.Up(keyboard.KeyF)
}
time.Sleep(16 * time.Millisecond)
}
}