Browse Source

Bugfixes

master
Tim Schuster 2 years ago
parent
commit
bde68f222c
Signed by: Tim Schuster <mail@timschuster.info> GPG Key ID: F9E27097EFB77F61
3 changed files with 14 additions and 8 deletions
  1. 7
    6
      example/main.go
  2. 1
    1
      helper.go
  3. 6
    1
      pca9685.go

+ 7
- 6
example/main.go View File

@@ -15,7 +15,7 @@ var bufin = bufio.NewReader(os.Stdin)
15 15
 func main() {
16 16
 	logger := log.New(os.Stderr, "PCA9685", log.LUTC|log.Llongfile)
17 17
 
18
-	p, err := adafruitPCA9685.NewPCA9685(nil, 0, logger)
18
+	p, err := adafruitPCA9685.NewPCA9685(nil, 1, logger)
19 19
 	if err != nil {
20 20
 		log.Fatal(err)
21 21
 		return
@@ -29,8 +29,12 @@ func main() {
29 29
 		return
30 30
 	}
31 31
 	fmt.Printf("Current Angle: %d °\n", servo.CurrentAngle())
32
-	var angle int16
33
-	for angle, err = parseKeyboardInput(stepsize, servo); err == nil; angle, err = parseKeyboardInput(stepsize, servo) {
32
+	for {
33
+		angle, err := parseKeyboardInput(stepsize, servo)
34
+		if err != nil {
35
+			fmt.Printf("Error: %s", err)
36
+			return
37
+		}
34 38
 		err = servo.TurnTo(angle)
35 39
 		if err != nil {
36 40
 			log.Fatal(err)
@@ -38,9 +42,6 @@ func main() {
38 42
 		}
39 43
 		fmt.Printf("Current Angle: %d °\n", servo.CurrentAngle())
40 44
 	}
41
-	if err != nil {
42
-		fmt.Printf("Error: %s", err)
43
-	}
44 45
 }
45 46
 
46 47
 func parseKeyboardInput(step int16, s *adafruitPCA9685.Servo) (int16, error) {

+ 1
- 1
helper.go View File

@@ -5,7 +5,7 @@ import (
5 5
 )
6 6
 
7 7
 func (p *PCA9685) WaitForOscillator() {
8
-	time.Sleep(200 * time.Millisecond)
8
+	time.Sleep(5 * time.Millisecond)
9 9
 }
10 10
 
11 11
 func (p *PCA9685) logDebug(msg ...interface{}) {

+ 6
- 1
pca9685.go View File

@@ -28,12 +28,17 @@ func NewPCA9685(addressPtr *int, bus byte, debug *log.Logger) (*PCA9685, error)
28 28
 	}
29 29
 	pca := &PCA9685{dev: d, debugger: debug}
30 30
 	pca.logDebug("Setting up Controller")
31
+	err = pca.SetAllPWM(0,0)
32
+	if err != nil {
33
+		pca.logDebug("Error on SetAllPWM : ", err)
34
+		return nil, err
35
+	}
31 36
 	err = pca.writeBReg(c_MODE2, c_OUTDRV)
32 37
 	if err != nil {
33 38
 		pca.logDebug("Error on write MODE2 OUTDRV : ", err)
34 39
 		return nil, err
35 40
 	}
36
-	err = pca.writeBReg(c_MODE2, c_ALLCALL)
41
+	err = pca.writeBReg(c_MODE1, c_ALLCALL)
37 42
 	if err != nil {
38 43
 		pca.logDebug("Error on write MODE2 ALLCALL : ", err)
39 44
 		return nil, err

Loading…
Cancel
Save