-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (32 loc) · 817 Bytes
/
Copy pathmain.go
File metadata and controls
40 lines (32 loc) · 817 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
package main
import (
"fmt"
"log"
"time"
"github.com/googolgl/go-i2c"
"github.com/googolgl/go-pca9685"
)
func main() {
// Create new connection to i2c-bus on 1 line with address 0x40.
// Use i2cdetect utility to find device address over the i2c-bus
fmt.Println("Hello world")
i2c, err := i2c.New(pca9685.Address, "/dev/i2c-1")
if err != nil {
log.Fatal(err)
}
pca0, err := pca9685.New(i2c, nil)
if err != nil {
log.Fatal(err)
}
// Sets a single PWM channel 0
pca0.SetChannel(1, 0, 130)
// Servo on channel 0
servo0 := pca0.ServoNew(1, nil)
// Angle in degrees. Must be in the range `0` to `Range`
for i := 0; i < 130; i++ {
servo0.Angle(i)
time.Sleep(10 * time.Millisecond)
}
// Fraction as pulse width expressed between 0.0 `MinPulse` and 1.0 `MaxPulse`
servo0.Fraction(0.5)
}