-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
70 lines (58 loc) · 1.05 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
package main
import (
"fmt"
"github.com/stianeikeland/go-rpio"
"os"
"os/signal"
"syscall"
"time"
)
func main() {
if err := rpio.Open(); err != nil {
fmt.Println(err)
os.Exit(1)
}
// Get the pin for each of the lights
redPin := rpio.Pin(9)
yellowPin := rpio.Pin(10)
greenPin := rpio.Pin(11)
// Set the pins to output mode
redPin.Output()
yellowPin.Output()
greenPin.Output()
// Clean up on ctrl-c and turn lights out
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
redPin.Low()
yellowPin.Low()
greenPin.Low()
os.Exit(0)
}()
defer rpio.Close()
// Turn lights off to start.
redPin.Low()
yellowPin.Low()
greenPin.Low()
// A while true loop.
for {
// Red
redPin.High()
time.Sleep(time.Second * 3)
// Red and yellow
yellowPin.High()
time.Sleep(time.Second)
// Green
redPin.Low()
yellowPin.Low()
greenPin.High()
time.Sleep(time.Second * 5)
// Yellow
greenPin.Low()
yellowPin.High()
time.Sleep(time.Second * 2)
// Yellow off
yellowPin.Low()
}
}