2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2017-05-06 02:12:52 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2017-05-06 02:12:52 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/drivers/gpio"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/intel-iot/joule"
|
2017-05-06 02:12:52 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
e := joule.NewAdaptor()
|
|
|
|
led := gpio.NewLedDriver(e, "J12_26")
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
brightness := uint8(0)
|
|
|
|
fadeAmount := uint8(15)
|
|
|
|
|
|
|
|
gobot.Every(100*time.Millisecond, func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := led.Brightness(brightness); err != nil {
|
2017-05-06 02:12:52 +08:00
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
brightness = brightness + fadeAmount
|
|
|
|
if brightness == 0 || brightness == 255 {
|
|
|
|
fadeAmount = -fadeAmount
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("pwmBot",
|
|
|
|
[]gobot.Connection{e},
|
|
|
|
[]gobot.Device{led},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2017-05-06 02:12:52 +08:00
|
|
|
}
|