hybridgroup.gobot/examples/raspi_mcp3008.go

39 lines
573 B
Go
Raw Normal View History

//go:build example
// +build example
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/spi"
"gobot.io/x/gobot/v2/platforms/raspi"
)
func main() {
a := raspi.NewAdaptor()
adc := spi.NewMCP3008Driver(a)
work := func() {
gobot.Every(100*time.Millisecond, func() {
result, err := adc.Read(0)
fmt.Println("A0", result, err)
})
}
robot := gobot.NewRobot("mcp3008bot",
[]gobot.Connection{a},
[]gobot.Device{adc},
work,
)
if err := robot.Start(); err != nil {
panic(err)
}
}