hybridgroup.gobot/examples/chip_grove_lcd.go

76 lines
1.5 KiB
Go
Raw Normal View History

//go:build example
// +build example
//
// Do not build by default.
2016-02-04 05:51:25 +08:00
package main
import (
"fmt"
2016-02-04 05:51:25 +08:00
"time"
"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() {
board := chip.NewAdaptor()
screen := i2c.NewGroveLcdDriver(board)
2016-02-04 05:51:25 +08:00
work := func() {
if err := screen.Write("hello"); err != nil {
fmt.Println(err)
}
2016-02-04 05:51:25 +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() {
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
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
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() {
if err := screen.Scroll(false); err != nil {
fmt.Println(err)
}
2016-02-04 05:51:25 +08:00
})
})
if err := screen.Home(); err != nil {
fmt.Println(err)
}
time.Sleep(1 * time.Second)
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,
)
if err := robot.Start(); err != nil {
panic(err)
}
2016-02-04 05:51:25 +08:00
}