gobot.io/x/gobot@v1.16.0/examples/gopigo3_servo.go (about)

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"time"
    10  
    11  	"gobot.io/x/gobot"
    12  	"gobot.io/x/gobot/drivers/gpio"
    13  	"gobot.io/x/gobot/platforms/dexter/gopigo3"
    14  	"gobot.io/x/gobot/platforms/raspi"
    15  )
    16  
    17  func main() {
    18  	raspiAdaptor := raspi.NewAdaptor()
    19  	gpg3 := gopigo3.NewDriver(raspiAdaptor)
    20  	servo := gpio.NewServoDriver(gpg3, "SERVO_1")
    21  
    22  	work := func() {
    23  		gobot.Every(1*time.Second, func() {
    24  			i := uint8(gobot.Rand(180))
    25  			fmt.Println("Turning", i)
    26  			servo.Move(i)
    27  		})
    28  
    29  	}
    30  
    31  	robot := gobot.NewRobot("gopigo3servo",
    32  		[]gobot.Connection{raspiAdaptor},
    33  		[]gobot.Device{gpg3, servo},
    34  		work,
    35  	)
    36  
    37  	robot.Start()
    38  }