-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpi-controller.go
More file actions
42 lines (33 loc) · 838 Bytes
/
pi-controller.go
File metadata and controls
42 lines (33 loc) · 838 Bytes
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
package main
import (
"fmt"
"time"
"github.com/stianeikeland/go-rpio"
)
func signalToFire() {
// Connect to Raspberry PI gpio (i.e. pins on the board)
logMessage("opening gpio")
err := rpio.Open()
if err != nil {
fmt.Println("GPIO is not available")
return
}
defer rpio.Close()
// Setup pins connected to the relays responsible for spinning the launch motor and the firing motor
spinPin := rpio.Pin(21)
firePin := rpio.Pin(20)
spinPin.Output()
firePin.Output()
// Spin up the firing motor so it is ready to fire
spinPin.High()
logMessage("gpio SPIN")
time.Sleep(500 * time.Millisecond)
// Fire the ball by sending the singal to start the fire relay
firePin.High()
logMessage("gpio FIRE")
time.Sleep(500 * time.Millisecond)
// Turn off the motors
firePin.Low()
spinPin.Low()
logMessage("gpio OFF")
}