hybridgroup.gobot/examples/firmata_blinkm.go

33 lines
680 B
Go
Raw Normal View History

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"
)
func main() {
2014-04-28 10:56:18 +08:00
firmataAdaptor := firmata.NewFirmataAdaptor()
firmataAdaptor.Name = "firmata"
firmataAdaptor.Port = "/dev/ttyACM0"
2014-04-28 10:56:18 +08:00
blinkm := i2c.NewBlinkMDriver(firmataAdaptor)
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},
Devices: []gobot.Device{blinkm},
Work: work,
}
robot.Start()
}