2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2018-09-06 02:13:14 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2018-09-06 02:13:14 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/drivers/i2c"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/upboard/up2"
|
2018-09-06 02:13:14 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
board := up2.NewAdaptor()
|
|
|
|
screen := i2c.NewGroveLcdDriver(board)
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
screen.Write("hello")
|
|
|
|
|
|
|
|
screen.SetRGB(255, 0, 0)
|
|
|
|
|
|
|
|
gobot.After(5*time.Second, func() {
|
|
|
|
screen.Clear()
|
|
|
|
screen.Home()
|
|
|
|
screen.SetRGB(0, 255, 0)
|
|
|
|
// set a custom character in the first position
|
|
|
|
screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"])
|
|
|
|
// add the custom character at the end of the string
|
|
|
|
screen.Write("goodbye\nhave a nice day " + string(byte(0)))
|
|
|
|
gobot.Every(500*time.Millisecond, func() {
|
|
|
|
screen.Scroll(false)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
screen.Home()
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
screen.SetRGB(0, 0, 255)
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("screenBot",
|
|
|
|
[]gobot.Connection{board},
|
|
|
|
[]gobot.Device{screen},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|