I was trying to test a LDR using gobot framework. I used AnalogSensorDriver device driver and my code is
package main
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/aio"
"gobot.io/x/gobot/platforms/raspi"
)
func main() {
r := raspi.NewAdaptor()
ldr := aio.AnalogSensorDriver(r, "7")
work := func() {
gobot.Every(1*time.Second, func() {
ldr.Read()
})
}
robot := gobot.NewRobot("getBot",
[]gobot.Connection{r},
[]gobot.Device{ldr},
work,
)
robot.Start()
}
When I execute this, I am getting this error.
./ldrtest.go:13: too many arguments to conversion to aio.AnalogSensorDriver: aio.AnalogSensorDriver(w, "7") ./ldrtest.go:22: undefined: w
I am totally new for golang and gobot. So any kind of help to solve this problem would be greatly appreciated.
Thanks in advance.
From a quick glance at
gobot's source it seems to me that you cannot useaio.NewAnalogSensorDriverwith theraspi.Adaptor. The aio.NewAnalogSensorDriver expects it's first argument to be aninterfaceof type AnalogReader while the raspi.NewAdaptor returns a raspi.Adaptor that, seemingly, does not implement the AnalogRead method required for it to implement theAnalogReaderinterface.That's why you get that error
./ldrtest.go:13: cannot use r (type *raspi.Adaptor) as type aio.AnalogReader in argument to aio.NewAnalogSensorDriver: *raspi.Adaptor does not implement aio.AnalogReader (missing AnalogRead method).Update: Making your code work depends on what you want to do. If you want to use
raspi.Adaptoryou cannot useaio.NewAnalogSensorDriverbecause theraspi.Adaptordoes not have analog capabilities. If you want to use theaio.NewAnalogSensorDriveryou'll need to use, as its first argument, a value whose type implements theAnalogReadmethod, like for example the beaglebone.Adaptor does.This example should get you past that initial error, if the code below causes other issues you should consider consulting the documentation for both Go and gobot.