hybridgroup.gobot/examples/beaglebone_led_brightness.go

38 lines
748 B
Go
Raw Normal View History

package main
import (
"github.com/hybridgroup/gobot"
2014-04-28 19:39:51 +08:00
"github.com/hybridgroup/gobot/beaglebone"
"github.com/hybridgroup/gobot/gpio"
)
func main() {
2014-04-28 19:39:51 +08:00
beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor()
beagleboneAdaptor.Name = "beaglebone"
2014-04-28 19:39:51 +08:00
led := gpio.NewLedDriver(beagleboneAdaptor)
led.Name = "led"
led.Pin = "P9_14"
work := func() {
brightness := uint8(0)
fade_amount := uint8(5)
gobot.Every("0.1s", func() {
led.Brightness(brightness)
brightness = brightness + fade_amount
if brightness == 0 || brightness == 255 {
fade_amount = -fade_amount
}
})
}
robot := gobot.Robot{
2014-04-28 19:39:51 +08:00
Connections: []gobot.Connection{beagleboneAdaptor},
Devices: []gobot.Device{led},
Work: work,
}
robot.Start()
}