-
Notifications
You must be signed in to change notification settings - Fork 0
/
led.go
65 lines (51 loc) · 954 Bytes
/
led.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
/*
A blinker example using go-rpio library.
Requires administrator rights to run
Toggles a LED on physical pin 19 (mcu pin 10)
Connect a LED with resistor from pin 19 to ground.
*/
package main
import (
"fmt"
"os"
"github.com/stianeikeland/go-rpio"
)
var (
// Use mcu pin 10, corresponds to physical pin 19 on the pi
pinRed = rpio.Pin(25)
pinGreen = rpio.Pin(24)
pinBlue = rpio.Pin(23)
)
func InitRgbLed() {
// Open and map memory to access gpio, check for errors
if err := rpio.Open(); err != nil {
fmt.Println(err)
os.Exit(1)
}
// Unmap gpio memory when done
defer rpio.Close()
// Set pin to output mode
pinRed.Output()
pinGreen.Output()
pinBlue.Output()
}
func Red() {
pinRed.High()
pinGreen.Low()
pinBlue.Low()
}
func Green() {
pinRed.Low()
pinGreen.High()
pinBlue.Low()
}
func Orange() {
pinRed.High()
pinGreen.Low()
pinBlue.High()
}
func InitRgbState() {
pinRed.Low()
pinGreen.Low()
pinBlue.Low()
}