-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhalloween-ghostfire.go
80 lines (66 loc) · 1.59 KB
/
halloween-ghostfire.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
package main
import (
"fmt"
"github.com/common-nighthawk/go-figure"
"log"
"github.com/jacobsa/go-serial/serial"
)
func main() {
// bulbhead
// poison
myFigure := figure.NewFigure("Halloween", "poison", true)
myFigure.Print()
fmt.Println()
fmt.Println()
myFigure = figure.NewFigure("Ghost Fire", "poison", true)
myFigure.Print()
fmt.Println()
fmt.Println()
fmt.Println()
figure.NewFigure("When a Ghost turns Red ", "doom", true).Print()
figure.NewFigure("you can shoot it", "doom", true).Print()
figure.NewFigure("Press the start button", "doom", true).Print()
// figure.NewFigure("Give your reasons", "doom", true).Blink(10000, 500, -1)
// Set up options.
options := serial.OpenOptions{
PortName: "/dev/cu.usbmodem144401",
BaudRate: 115200,
DataBits: 8,
StopBits: 1,
MinimumReadSize: 4,
}
// Open the port.
port, err := serial.Open(options)
if err != nil {
log.Fatalf("serial.Open: %v", err)
}
// Make sure to close it later.
defer port.Close()
// // Write 4 bytes to the port.
// b := []byte{0x00, 0x01, 0x02, 0x03}
// n, err := port.Write(b)
// if err != nil {
// log.Fatalf("port.Write: %v", err)
// }
// fmt.Println("Wrote", n, "bytes.")
for {
buf := make([]byte, 1)
n, err := port.Read(buf)
if err != nil {
log.Fatal(err)
}
ar := fmt.Sprintf("%s", buf[:n])
fmt.Println("GOT COMMAND :" + ar)
if ar == "E" {
b := []byte("NG")
n, err := port.Write(b)
if err != nil {
log.Fatalf("port.Write: %v", err)
}
fmt.Println("Wrote", n, "bytes.")
}
if ar == "R" {
fmt.Println("Round End")
}
}
}