2015-10-23 07:56:03 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/api"
|
|
|
|
"gobot.io/x/gobot/drivers/gpio"
|
|
|
|
"gobot.io/x/gobot/platforms/intel-iot/edison"
|
2015-10-23 07:56:03 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-19 03:08:25 +08:00
|
|
|
master := gobot.NewMaster()
|
|
|
|
a := api.NewAPI(master)
|
2015-10-23 07:56:03 +08:00
|
|
|
a.Start()
|
|
|
|
|
2016-10-03 22:58:43 +08:00
|
|
|
board := edison.NewAdaptor()
|
|
|
|
red := gpio.NewLedDriver(board, "3")
|
|
|
|
green := gpio.NewLedDriver(board, "5")
|
|
|
|
blue := gpio.NewLedDriver(board, "6")
|
2015-10-23 07:56:03 +08:00
|
|
|
|
2016-10-03 22:58:43 +08:00
|
|
|
button := gpio.NewButtonDriver(board, "7")
|
2015-10-23 07:56:03 +08:00
|
|
|
|
|
|
|
enabled := true
|
|
|
|
work := func() {
|
|
|
|
red.Brightness(0xff)
|
|
|
|
green.Brightness(0x00)
|
|
|
|
blue.Brightness(0x00)
|
|
|
|
|
|
|
|
flash := false
|
|
|
|
on := true
|
|
|
|
|
|
|
|
gobot.Every(250*time.Millisecond, func() {
|
|
|
|
if enabled {
|
|
|
|
if flash {
|
|
|
|
if on {
|
|
|
|
red.Brightness(0x00)
|
|
|
|
green.Brightness(0xff)
|
|
|
|
blue.Brightness(0x00)
|
|
|
|
on = false
|
|
|
|
} else {
|
|
|
|
red.Brightness(0xff)
|
|
|
|
green.Brightness(0x00)
|
|
|
|
blue.Brightness(0x00)
|
|
|
|
on = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2016-09-01 18:17:43 +08:00
|
|
|
button.On(gpio.ButtonPush, func(data interface{}) {
|
2015-10-23 07:56:03 +08:00
|
|
|
flash = true
|
|
|
|
})
|
|
|
|
|
2016-09-01 18:17:43 +08:00
|
|
|
button.On(gpio.ButtonRelease, func(data interface{}) {
|
2015-10-23 07:56:03 +08:00
|
|
|
flash = false
|
|
|
|
red.Brightness(0x00)
|
|
|
|
green.Brightness(0x00)
|
|
|
|
blue.Brightness(0xff)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot(
|
|
|
|
"square of fire",
|
|
|
|
[]gobot.Connection{board},
|
|
|
|
[]gobot.Device{red, green, blue, button},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
robot.AddCommand("enable", func(params map[string]interface{}) interface{} {
|
|
|
|
enabled = !enabled
|
|
|
|
return enabled
|
|
|
|
})
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
master.AddRobot(robot)
|
2015-10-23 07:56:03 +08:00
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
master.Start()
|
2015-10-23 07:56:03 +08:00
|
|
|
}
|