2014-04-26 18:11:51 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/hybridgroup/gobot"
|
2014-04-28 10:56:18 +08:00
|
|
|
"github.com/hybridgroup/gobot/firmata"
|
|
|
|
"github.com/hybridgroup/gobot/i2c"
|
2014-04-26 18:11:51 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-04-28 10:56:18 +08:00
|
|
|
firmataAdaptor := firmata.NewFirmataAdaptor()
|
|
|
|
firmataAdaptor.Name = "firmata"
|
|
|
|
firmataAdaptor.Port = "/dev/ttyACM0"
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-04-28 10:56:18 +08:00
|
|
|
blinkm := i2c.NewBlinkMDriver(firmataAdaptor)
|
2014-04-26 18:11:51 +08:00
|
|
|
blinkm.Name = "blinkm"
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every("3s", func() {
|
|
|
|
blinkm.Rgb(byte(gobot.Rand(255)), byte(gobot.Rand(255)), byte(gobot.Rand(255)))
|
|
|
|
fmt.Println("color", blinkm.Color())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.Robot{
|
2014-04-28 10:56:18 +08:00
|
|
|
Connections: []gobot.Connection{firmataAdaptor},
|
2014-04-26 18:11:51 +08:00
|
|
|
Devices: []gobot.Device{blinkm},
|
|
|
|
Work: work,
|
|
|
|
}
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|