2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2017-04-26 21:54:59 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2017-04-26 21:54:59 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-11 22:34:50 +08:00
|
|
|
"fmt"
|
2017-04-26 21:54:59 +08:00
|
|
|
"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/tinkerboard"
|
2017-04-26 21:54:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
board := tinkerboard.NewAdaptor()
|
|
|
|
screen := i2c.NewGroveLcdDriver(board)
|
|
|
|
|
|
|
|
work := func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.Write("Hello from"); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2017-04-26 21:54:59 +08:00
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.SetRGB(255, 0, 0); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2017-04-26 21:54:59 +08:00
|
|
|
|
|
|
|
gobot.After(5*time.Second, func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.Clear(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
if err := screen.Home(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
if err := screen.SetRGB(0, 255, 0); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2017-04-26 21:54:59 +08:00
|
|
|
// set a custom character in the first position
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"]); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2017-04-26 21:54:59 +08:00
|
|
|
// add the custom character at the end of the string
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.Write("\nTinker Board " + string(byte(0))); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2017-04-26 21:54:59 +08:00
|
|
|
gobot.Every(500*time.Millisecond, func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.Scroll(false); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2017-04-26 21:54:59 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.Home(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2017-04-26 21:54:59 +08:00
|
|
|
time.Sleep(1 * time.Second)
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.SetRGB(0, 0, 255); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2017-04-26 21:54:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("screenBot",
|
|
|
|
[]gobot.Connection{board},
|
|
|
|
[]gobot.Device{screen},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2017-04-26 21:54:59 +08:00
|
|
|
}
|