2014-04-26 18:11:51 +08:00
|
|
|
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"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-04-28 19:23:15 +08:00
|
|
|
digisparkAdaptor := digispark.NewDigisparkAdaptor()
|
|
|
|
digisparkAdaptor.Name = "digispark"
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-04-28 19:23:15 +08:00
|
|
|
led := gpio.NewLedDriver(digisparkAdaptor)
|
2014-04-26 18:11:51 +08:00
|
|
|
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},
|
2014-04-26 18:11:51 +08:00
|
|
|
Devices: []gobot.Device{led},
|
|
|
|
Work: work,
|
|
|
|
}
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|