2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2017-03-13 23:01:39 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2016-02-04 05:51:25 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-11 22:34:50 +08:00
|
|
|
"fmt"
|
2016-02-04 05:51:25 +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/chip"
|
2016-02-04 05:51:25 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-03 22:58:43 +08:00
|
|
|
board := chip.NewAdaptor()
|
|
|
|
screen := i2c.NewGroveLcdDriver(board)
|
2016-02-04 05:51:25 +08:00
|
|
|
|
|
|
|
work := func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.Write("hello"); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2016-02-04 05:51:25 +08:00
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.SetRGB(255, 0, 0); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2016-02-04 05:51:25 +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)
|
|
|
|
}
|
2016-02-04 05:51:25 +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)
|
|
|
|
}
|
2016-02-04 05:51:25 +08:00
|
|
|
// add the custom character at the end of the string
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.Write("goodbye\nhave a nice day " + string(byte(0))); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
|
2016-02-04 05:51:25 +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)
|
|
|
|
}
|
2016-02-04 05:51:25 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := screen.Home(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2016-11-05 20:05:49 +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)
|
|
|
|
}
|
2016-02-04 05:51:25 +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)
|
|
|
|
}
|
2016-02-04 05:51:25 +08:00
|
|
|
}
|