2014-04-26 03:11:51 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hybridgroup/gobot"
|
2014-05-22 19:32:09 -07:00
|
|
|
"github.com/hybridgroup/gobot/platforms/beaglebone"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/gpio"
|
|
|
|
"time"
|
2014-04-26 03:11:51 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-05-22 19:32:09 -07:00
|
|
|
gbot := gobot.NewGobot()
|
|
|
|
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone")
|
2014-07-08 18:36:14 -07:00
|
|
|
led := gpio.NewLedDriver("led", beagleboneAdaptor, "P9_14")
|
2014-04-26 03:11:51 -07:00
|
|
|
|
|
|
|
work := func() {
|
|
|
|
brightness := uint8(0)
|
2014-06-10 15:16:11 -07:00
|
|
|
fadeAmount := uint8(5)
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2014-06-06 13:18:07 -07:00
|
|
|
gobot.Every(100*time.Millisecond, func() {
|
2014-04-26 03:11:51 -07:00
|
|
|
led.Brightness(brightness)
|
2014-06-10 15:16:11 -07:00
|
|
|
brightness = brightness + fadeAmount
|
2014-04-26 03:11:51 -07:00
|
|
|
if brightness == 0 || brightness == 255 {
|
2014-06-10 15:16:11 -07:00
|
|
|
fadeAmount = -fadeAmount
|
2014-04-26 03:11:51 -07:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-08 18:36:14 -07:00
|
|
|
robot := gobot.NewRobot("pwmBot",
|
|
|
|
[]gobot.Connection{beagleboneAdaptor},
|
|
|
|
[]gobot.Device{led},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
2014-05-22 19:32:09 -07:00
|
|
|
gbot.Start()
|
2014-04-26 03:11:51 -07:00
|
|
|
}
|