hybridgroup.gobot/examples/digispark_led_brightness.go

38 lines
737 B
Go
Raw Normal View History

package main
import (
"github.com/hybridgroup/gobot"
2014-04-28 19:23:15 +08:00
"github.com/hybridgroup/gobot/digispark"
"github.com/hybridgroup/gobot/gpio"
)
func main() {
2014-04-28 19:23:15 +08:00
digisparkAdaptor := digispark.NewDigisparkAdaptor()
digisparkAdaptor.Name = "digispark"
2014-04-28 19:23:15 +08:00
led := gpio.NewLedDriver(digisparkAdaptor)
led.Name = "led"
led.Pin = "0"
work := func() {
brightness := uint8(0)
fade_amount := uint8(15)
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:23:15 +08:00
Connections: []gobot.Connection{digisparkAdaptor},
Devices: []gobot.Device{led},
Work: work,
}
robot.Start()
}