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)
func main() {
logger := log.New(os.Stderr, "PCA9685", log.LUTC|log.Llongfile)

p, err := adafruitPCA9685.NewPCA9685(nil, 0, logger)
p, err := adafruitPCA9685.NewPCA9685(nil, 1, logger)
if err != nil {
log.Fatal(err)
return
@@ -29,8 +29,12 @@ func main() {
return
}
fmt.Printf("Current Angle: %d °\n", servo.CurrentAngle())
var angle int16
for angle, err = parseKeyboardInput(stepsize, servo); err == nil; angle, err = parseKeyboardInput(stepsize, servo) {
for {
angle, err := parseKeyboardInput(stepsize, servo)
if err != nil {
fmt.Printf("Error: %s", err)
return
}
err = servo.TurnTo(angle)
if err != nil {
log.Fatal(err)
@@ -38,9 +42,6 @@ func main() {
}
fmt.Printf("Current Angle: %d °\n", servo.CurrentAngle())
}
if err != nil {
fmt.Printf("Error: %s", err)
}
}

func parseKeyboardInput(step int16, s *adafruitPCA9685.Servo) (int16, error) {

+ 1
- 1
helper.go View File

@@ -5,7 +5,7 @@ import (
)

func (p *PCA9685) WaitForOscillator() {
time.Sleep(200 * time.Millisecond)
time.Sleep(5 * time.Millisecond)
}

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)
}
pca := &PCA9685{dev: d, debugger: debug}
pca.logDebug("Setting up Controller")
err = pca.SetAllPWM(0,0)
if err != nil {
pca.logDebug("Error on SetAllPWM : ", err)
return nil, err
}
err = pca.writeBReg(c_MODE2, c_OUTDRV)
if err != nil {
pca.logDebug("Error on write MODE2 OUTDRV : ", err)
return nil, err
}
err = pca.writeBReg(c_MODE2, c_ALLCALL)
err = pca.writeBReg(c_MODE1, c_ALLCALL)
if err != nil {
pca.logDebug("Error on write MODE2 ALLCALL : ", err)
return nil, err

Loading…
Cancel
Save