gobot.io/x/gobot/v2@v2.1.0/examples/chip_grove_lcd.go (about)

     1  //go:build example
     2  // +build example
     3  
     4  //
     5  // Do not build by default.
     6  
     7  package main
     8  
     9  import (
    10  	"time"
    11  
    12  	"gobot.io/x/gobot/v2"
    13  	"gobot.io/x/gobot/v2/drivers/i2c"
    14  	"gobot.io/x/gobot/v2/platforms/chip"
    15  )
    16  
    17  func main() {
    18  	board := chip.NewAdaptor()
    19  	screen := i2c.NewGroveLcdDriver(board)
    20  
    21  	work := func() {
    22  		screen.Write("hello")
    23  
    24  		screen.SetRGB(255, 0, 0)
    25  
    26  		gobot.After(5*time.Second, func() {
    27  			screen.Clear()
    28  			screen.Home()
    29  			screen.SetRGB(0, 255, 0)
    30  			// set a custom character in the first position
    31  			screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"])
    32  			// add the custom character at the end of the string
    33  			screen.Write("goodbye\nhave a nice day " + string(byte(0)))
    34  			gobot.Every(500*time.Millisecond, func() {
    35  				screen.Scroll(false)
    36  			})
    37  		})
    38  
    39  		screen.Home()
    40  		time.Sleep(1 * time.Second)
    41  		screen.SetRGB(0, 0, 255)
    42  	}
    43  
    44  	robot := gobot.NewRobot("screenBot",
    45  		[]gobot.Connection{board},
    46  		[]gobot.Device{screen},
    47  		work,
    48  	)
    49  
    50  	robot.Start()
    51  }