2023-05-20 14:25:21 +02:00
|
|
|
//go:build example
|
2018-08-24 21:00:51 +02:00
|
|
|
// +build example
|
2023-05-20 14:25:21 +02:00
|
|
|
|
2018-08-24 21:00:51 +02:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2023-05-20 14:25:21 +02:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/drivers/i2c"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/digispark"
|
2018-08-24 21:00:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
board := digispark.NewAdaptor()
|
|
|
|
blinkm := i2c.NewBlinkMDriver(board)
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(3*time.Second, func() {
|
|
|
|
r := byte(gobot.Rand(255))
|
|
|
|
g := byte(gobot.Rand(255))
|
|
|
|
b := byte(gobot.Rand(255))
|
2024-02-11 15:34:50 +01:00
|
|
|
if err := blinkm.Rgb(r, g, b); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
color, err := blinkm.Color()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2018-08-24 21:00:51 +02:00
|
|
|
fmt.Println("color", color)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("blinkBot",
|
|
|
|
[]gobot.Connection{board},
|
|
|
|
[]gobot.Device{blinkm},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2024-02-11 15:34:50 +01:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
2018-08-24 21:00:51 +02:00
|
|
|
}
|
|
|
|
}
|