gobot.io/x/gobot@v1.16.0/examples/firmata_ssd1306.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 package main 6 7 import ( 8 "fmt" 9 "os" 10 "time" 11 12 "gobot.io/x/gobot" 13 "gobot.io/x/gobot/drivers/i2c" 14 "gobot.io/x/gobot/platforms/firmata" 15 ) 16 17 func main() { 18 19 r := firmata.NewAdaptor(os.Args[1]) 20 oled := i2c.NewSSD1306Driver(r, i2c.WithAddress(0x3c)) 21 22 stage := false 23 24 work := func() { 25 26 gobot.Every(1*time.Second, func() { 27 fmt.Println("displaying") 28 oled.Clear() 29 if stage { 30 for x := 0; x < oled.Buffer.Width; x += 5 { 31 for y := 0; y < oled.Buffer.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 }