gobot.io/x/gobot/v2@v2.1.0/examples/raspi_mcp3008.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 "time" 12 13 "gobot.io/x/gobot/v2" 14 "gobot.io/x/gobot/v2/drivers/spi" 15 "gobot.io/x/gobot/v2/platforms/raspi" 16 ) 17 18 func main() { 19 a := raspi.NewAdaptor() 20 adc := spi.NewMCP3008Driver(a) 21 22 work := func() { 23 gobot.Every(100*time.Millisecond, func() { 24 result, err := adc.Read(0) 25 fmt.Println("A0", result, err) 26 }) 27 } 28 29 robot := gobot.NewRobot("mcp3008bot", 30 []gobot.Connection{a}, 31 []gobot.Device{adc}, 32 work, 33 ) 34 35 robot.Start() 36 }