examples: correct build errors in all current examples

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2017-04-04 13:38:51 +02:00
parent 9a2c94a50d
commit a3c892ee58
8 changed files with 66 additions and 12 deletions

View File

@ -8,13 +8,14 @@ import (
"fmt"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/aio"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/beaglebone"
)
func main() {
beagleboneAdaptor := beaglebone.NewAdaptor()
sensor := gpio.NewAnalogSensorDriver(beagleboneAdaptor, "P9_33")
sensor := aio.NewAnalogSensorDriver(beagleboneAdaptor, "P9_33")
led := gpio.NewLedDriver(beagleboneAdaptor, "P9_14")
work := func() {

View File

@ -17,17 +17,17 @@ func main() {
button := gpio.NewButtonDriver(dragonAdaptor, "GPIO_A")
work := func() {
gobot.On(button.Event("push"), func(data interface{}) {
button.On(gpio.ButtonPush, func(data interface{}) {
fmt.Println("button pressed")
})
gobot.On(button.Event("release"), func(data interface{}) {
button.On(gpio.ButtonRelease, func(data interface{}) {
fmt.Println("button released")
})
}
robot := gobot.NewRobot("buttonBot",
[]gobot.Connection{chipAdaptor},
[]gobot.Connection{dragonAdaptor},
[]gobot.Device{button},
work,
)

View File

@ -35,5 +35,5 @@ func main() {
work,
)
master.Start()
robot.Start()
}

View File

@ -9,6 +9,7 @@ import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/aio"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
)
@ -18,7 +19,7 @@ func main() {
led1 := gpio.NewLedDriver(firmataAdaptor, "3")
led2 := gpio.NewLedDriver(firmataAdaptor, "4")
button := gpio.NewButtonDriver(firmataAdaptor, "2")
sensor := gpio.NewAnalogSensorDriver(firmataAdaptor, "0")
sensor := aio.NewAnalogSensorDriver(firmataAdaptor, "0")
work := func() {
gobot.Every(1*time.Second, func() {
@ -33,7 +34,7 @@ func main() {
button.On(gpio.ButtonRelease, func(data interface{}) {
led2.Off()
})
sensor.On(gpio.Data, func(data interface{}) {
sensor.On(aio.Data, func(data interface{}) {
fmt.Println("sensor", data)
})
}

View File

@ -8,17 +8,18 @@ import (
"fmt"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/aio"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
)
func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
sensor := gpio.NewAnalogSensorDriver(firmataAdaptor, "0")
sensor := aio.NewAnalogSensorDriver(firmataAdaptor, "0")
led := gpio.NewLedDriver(firmataAdaptor, "3")
work := func() {
sensor.On(gpio.Data, func(data interface{}) {
sensor.On(aio.Data, func(data interface{}) {
brightness := uint8(
gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1024), 0, 255),
)

View File

@ -19,8 +19,11 @@ func main() {
work := func() {
gobot.Every(1*time.Second, func() {
fmt.Println("Pressure", mpl115a2.Pressure())
fmt.Println("Temperature", mpl115a2.Temperature())
press, _ := mpl115a2.Pressure()
fmt.Println("Pressure", press)
temp, _ := mpl115a2.Temperature()
fmt.Println("Temperature", temp)
})
}

View File

@ -0,0 +1,48 @@
// +build example
//
// Do not build by default.
package main
import (
"fmt"
"os"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/i2c"
"gobot.io/x/gobot/platforms/firmata"
)
func main() {
r := firmata.NewAdaptor(os.Args[1])
oled := i2c.NewSSD1306Driver(r, i2c.WithAddress(0x3c))
stage := false
work := func() {
gobot.Every(1*time.Second, func() {
fmt.Println("displaying")
oled.Clear()
if stage {
for x := 0; x < oled.Buffer.Width; x += 5 {
for y := 0; y < oled.Buffer.Height; y++ {
oled.Set(x, y, 1)
}
}
}
stage = !stage
oled.Display()
})
}
robot := gobot.NewRobot("ssd1306Robot",
[]gobot.Connection{r},
[]gobot.Device{oled},
work,
)
robot.Start()
}

View File

@ -47,7 +47,7 @@ func main() {
robot := gobot.NewRobot("mqttBot",
[]gobot.Connection{mqttAdaptor},
[]gobot.Devices{helloDriver, holaDriver},
[]gobot.Device{helloDriver, holaDriver},
work,
)