2014-04-26 03:11:51 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-07-09 16:51:00 -07:00
|
|
|
"time"
|
|
|
|
|
2014-04-26 03:11:51 -07:00
|
|
|
"github.com/hybridgroup/gobot"
|
2016-10-03 16:58:43 +02:00
|
|
|
"github.com/hybridgroup/gobot/drivers/gpio"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/particle"
|
2014-04-26 03:11:51 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-15 20:02:54 +02:00
|
|
|
gbot := gobot.NewMaster()
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2016-10-03 16:58:43 +02:00
|
|
|
core := particle.NewAdaptor("device_id", "access_token")
|
|
|
|
led := gpio.NewLedDriver(core, "A1")
|
2014-04-26 03:11:51 -07:00
|
|
|
|
|
|
|
work := func() {
|
|
|
|
brightness := uint8(0)
|
2014-06-10 15:16:11 -07:00
|
|
|
fadeAmount := uint8(25)
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2014-06-08 18:37:14 -07:00
|
|
|
gobot.Every(500*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("spark",
|
2016-10-03 16:58:43 +02:00
|
|
|
[]gobot.Connection{core},
|
2014-07-08 18:36:14 -07:00
|
|
|
[]gobot.Device{led},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
|
|
|
|
|
|
|
gbot.Start()
|
2014-04-26 03:11:51 -07:00
|
|
|
}
|