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