gobot.io/x/gobot@v1.16.0/examples/raspi_mcp3008.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 package main 6 7 import ( 8 "fmt" 9 "time" 10 11 "gobot.io/x/gobot" 12 "gobot.io/x/gobot/drivers/spi" 13 "gobot.io/x/gobot/platforms/raspi" 14 ) 15 16 func main() { 17 a := raspi.NewAdaptor() 18 adc := spi.NewMCP3008Driver(a) 19 20 work := func() { 21 gobot.Every(100*time.Millisecond, func() { 22 result, err := adc.Read(0) 23 fmt.Println("A0", result, err) 24 }) 25 } 26 27 robot := gobot.NewRobot("mcp3008bot", 28 []gobot.Connection{a}, 29 []gobot.Device{adc}, 30 work, 31 ) 32 33 robot.Start() 34 }