gobot.io/x/gobot@v1.16.0/examples/firmata_grove_lcd.go (about)

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