hybridgroup.gobot/examples/chip_grove_lcd.go

50 lines
995 B
Go
Raw Normal View History

2016-02-04 05:51:25 +08:00
package main
import (
"time"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/chip"
"github.com/hybridgroup/gobot/platforms/i2c"
2016-02-04 05:51:25 +08:00
)
func main() {
gbot := gobot.NewGobot()
board := chip.NewChipAdaptor("chip")
screen := i2c.NewGroveLcdDriver(board, "screen")
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.After(1 * time.Second)
screen.SetRGB(0, 0, 255)
}
robot := gobot.NewRobot("screenBot",
[]gobot.Connection{board},
[]gobot.Device{screen},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}