mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-27 13:48:56 +08:00
53 lines
871 B
Go
53 lines
871 B
Go
![]() |
package main
|
||
|
|
||
|
//
|
||
|
// before to run
|
||
|
// 1. check Jetson io pwm pin configure `sudo /opt/nvidia/jetson-io/jetson-io.py`
|
||
|
// 2. if end pin configure, reboot Jetson nano.
|
||
|
// 3. run gobot
|
||
|
import (
|
||
|
"log"
|
||
|
"time"
|
||
|
|
||
|
"gobot.io/x/gobot"
|
||
|
"gobot.io/x/gobot/drivers/gpio"
|
||
|
"gobot.io/x/gobot/platforms/jetson"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
|
||
|
jetsonAdaptor := jetson.NewAdaptor()
|
||
|
servo := gpio.NewServoDriver(jetsonAdaptor, "32")
|
||
|
|
||
|
counter := 0
|
||
|
flg := true
|
||
|
work := func() {
|
||
|
gobot.Every(100*time.Millisecond, func() {
|
||
|
|
||
|
log.Println("Turning", counter)
|
||
|
servo.Move(uint8(counter))
|
||
|
if counter == 140 {
|
||
|
flg = false
|
||
|
} else if counter == 30 {
|
||
|
flg = true
|
||
|
}
|
||
|
|
||
|
if flg {
|
||
|
counter = counter + 1
|
||
|
} else {
|
||
|
counter = counter - 1
|
||
|
|
||
|
}
|
||
|
})
|
||
|
|
||
|
}
|
||
|
|
||
|
robot := gobot.NewRobot("Jetsonservo",
|
||
|
[]gobot.Connection{jetsonAdaptor},
|
||
|
[]gobot.Device{servo},
|
||
|
work,
|
||
|
)
|
||
|
|
||
|
robot.Start()
|
||
|
}
|