gobot.io/x/gobot/v2@v2.1.0/examples/raspi_ssd1306.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/raspi" 15 ) 16 17 func main() { 18 width := 128 19 height := 32 20 r := raspi.NewAdaptor() 21 oled := i2c.NewSSD1306Driver(r, i2c.WithSSD1306DisplayWidth(width), i2c.WithSSD1306DisplayHeight(height)) 22 23 stage := false 24 25 work := func() { 26 27 gobot.Every(1*time.Second, func() { 28 oled.Clear() 29 if stage { 30 for x := 0; x < width; x += 5 { 31 for y := 0; y < height; y++ { 32 oled.Set(x, y, 1) 33 } 34 } 35 } 36 stage = !stage 37 oled.Display() 38 }) 39 } 40 41 robot := gobot.NewRobot("ssd1306Robot", 42 []gobot.Connection{r}, 43 []gobot.Device{oled}, 44 work, 45 ) 46 47 robot.Start() 48 }