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

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"time"
     9  
    10  	"gobot.io/x/gobot"
    11  	"gobot.io/x/gobot/drivers/i2c"
    12  	"gobot.io/x/gobot/platforms/raspi"
    13  )
    14  
    15  func main() {
    16  	width := 128
    17  	height := 32
    18  	r := raspi.NewAdaptor()
    19  	oled := i2c.NewSSD1306Driver(r, i2c.WithSSD1306DisplayWidth(width), i2c.WithSSD1306DisplayHeight(height))
    20  
    21  	stage := false
    22  
    23  	work := func() {
    24  
    25  		gobot.Every(1*time.Second, func() {
    26  			oled.Clear()
    27  			if stage {
    28  				for x := 0; x < width; x += 5 {
    29  					for y := 0; y < height; y++ {
    30  						oled.Set(x, y, 1)
    31  					}
    32  				}
    33  			}
    34  			stage = !stage
    35  			oled.Display()
    36  		})
    37  	}
    38  
    39  	robot := gobot.NewRobot("ssd1306Robot",
    40  		[]gobot.Connection{r},
    41  		[]gobot.Device{oled},
    42  		work,
    43  	)
    44  
    45  	robot.Start()
    46  }