docs: add examples for i2c platforms to use BlinkM

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2017-02-08 11:34:25 +01:00
parent 205f7186c6
commit 3e9250c585
3 changed files with 36 additions and 2 deletions

View File

@ -14,7 +14,7 @@ func main() {
blinkm := i2c.NewBlinkMDriver(beagleboneAdaptor) blinkm := i2c.NewBlinkMDriver(beagleboneAdaptor)
work := func() { work := func() {
gobot.Every(3*time.Second, func() { gobot.Every(1*time.Second, func() {
r := byte(gobot.Rand(255)) r := byte(gobot.Rand(255))
g := byte(gobot.Rand(255)) g := byte(gobot.Rand(255))
b := byte(gobot.Rand(255)) b := byte(gobot.Rand(255))

34
examples/chip_blinkm.go Normal file
View File

@ -0,0 +1,34 @@
package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/i2c"
"gobot.io/x/gobot/platforms/chip"
)
func main() {
a := chip.NewAdaptor()
blinkm := i2c.NewBlinkMDriver(a)
work := func() {
gobot.Every(1*time.Second, func() {
r := byte(gobot.Rand(255))
g := byte(gobot.Rand(255))
b := byte(gobot.Rand(255))
blinkm.Rgb(r, g, b)
color, _ := blinkm.Color()
fmt.Println("color", color)
})
}
robot := gobot.NewRobot("blinkmBot",
[]gobot.Connection{a},
[]gobot.Device{blinkm},
work,
)
robot.Start()
}

View File

@ -14,7 +14,7 @@ func main() {
blinkm := i2c.NewBlinkMDriver(r) blinkm := i2c.NewBlinkMDriver(r)
work := func() { work := func() {
gobot.Every(3*time.Second, func() { gobot.Every(1*time.Second, func() {
r := byte(gobot.Rand(255)) r := byte(gobot.Rand(255))
g := byte(gobot.Rand(255)) g := byte(gobot.Rand(255))
b := byte(gobot.Rand(255)) b := byte(gobot.Rand(255))