Skip to content

Commit

Permalink
examples: correct build errors in all current examples
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Apr 4, 2017
1 parent 9a2c94a commit a3c892e
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 12 deletions.
3 changes: 2 additions & 1 deletion examples/beaglebone_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions examples/dragonboard_button.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion examples/edison_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ func main() {
work,
)

master.Start()
robot.Start()
}
5 changes: 3 additions & 2 deletions examples/firmata_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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() {
Expand All @@ -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)
})
}
Expand Down
5 changes: 3 additions & 2 deletions examples/firmata_led_brightness_with_analog_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down
7 changes: 5 additions & 2 deletions examples/firmata_mpl115a2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down
48 changes: 48 additions & 0 deletions examples/firmata_ssd1306.go
Original file line number Diff line number Diff line change
@@ -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()
}
2 changes: 1 addition & 1 deletion examples/mqtt_driver_ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {

robot := gobot.NewRobot("mqttBot",
[]gobot.Connection{mqttAdaptor},
[]gobot.Devices{helloDriver, holaDriver},
[]gobot.Device{helloDriver, holaDriver},
work,
)

Expand Down

0 comments on commit a3c892e

Please sign in to comment.