Skip to content

Commit

Permalink
Merge pull request hybridgroup#452 from ulisesflynn/grove
Browse files Browse the repository at this point in the history
Added grove support, and more gopigo3 examples
  • Loading branch information
deadprogram authored Sep 29, 2017
2 parents 50c3d42 + 80f89f5 commit 6fbf176
Show file tree
Hide file tree
Showing 8 changed files with 892 additions and 85 deletions.
12 changes: 6 additions & 6 deletions examples/gopigo3.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@ import (
"time"

"gobot.io/x/gobot"
g "gobot.io/x/gobot/platforms/dexter/gopigo3"
"gobot.io/x/gobot/platforms/dexter/gopigo3"
"gobot.io/x/gobot/platforms/raspi"
)

func main() {
raspiAdaptor := raspi.NewAdaptor()
gopigo3 := g.NewDriver(raspiAdaptor)
gpg3 := g.NewDriver(raspiAdaptor)

work := func() {
on := uint8(0xFF)
gobot.Every(1000*time.Millisecond, func() {
err := gopigo3.SetLED(g.LED_EYE_RIGHT, 0x00, 0x00, on)
err := gpg3.SetLED(g.LED_EYE_RIGHT, 0x00, 0x00, on)
if err != nil {
fmt.Println(err)
}
err = gopigo3.SetLED(g.LED_EYE_LEFT, ^on, 0x00, 0x00)
err = gpg3.SetLED(g.LED_EYE_LEFT, ^on, 0x00, 0x00)
if err != nil {
fmt.Println(err)
}
on = ^on
})
}

robot := gobot.NewRobot("gopigo3",
robot := gobot.NewRobot("gopigo3eyeleds",
[]gobot.Connection{raspiAdaptor},
[]gobot.Device{gopigo3},
[]gobot.Device{gpg3},
work,
)

Expand Down
40 changes: 40 additions & 0 deletions examples/gopigo3_grove_button.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// +build example
//
// Do not build by default.

package main

import (
"fmt"

"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/dexter/gopigo3"
"gobot.io/x/gobot/platforms/raspi"
)

func main() {
raspiAdaptor := raspi.NewAdaptor()
gpg3 := gopigo3.NewDriver(raspiAdaptor)
led := gpio.NewGroveLedDriver(gpg3, "AD_1_1")
button := gpio.NewGroveButtonDriver(gpg3, "AD_2_1")

work := func() {
button.On(gpio.ButtonPush, func(data interface{}) {
fmt.Println("On!")
led.On()
})
button.On(gpio.ButtonRelease, func(data interface{}) {
fmt.Println("Off!")
led.Off()
})
}

robot := gobot.NewRobot("gopigo3button",
[]gobot.Connection{raspiAdaptor},
[]gobot.Device{gpg3, button, led},
work,
)

robot.Start()
}
40 changes: 40 additions & 0 deletions examples/gopigo3_grove_lcd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// +build example
//
// Do not build by default.

package main

import (
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/i2c"
"gobot.io/x/gobot/platforms/dexter/gopigo3"
"gobot.io/x/gobot/platforms/raspi"
)

func main() {
raspiAdaptor := raspi.NewAdaptor()
gpg3 := gopigo3.NewDriver(raspiAdaptor)
screen := i2c.NewGroveLcdDriver(raspiAdaptor)

work := func() {
manufacturerName := ""
boardName := ""
hardwareVersion := ""
manufacturerName, _ = gpg3.GetManufacturerName()
boardName, _ = gpg3.GetBoardName()
hardwareVersion, _ = gpg3.GetHardwareVersion()
screen.Write(manufacturerName[0:15])
screen.SetPosition(16)
screen.Write(boardName + " " + hardwareVersion)
screen.SetRGB(0, 0, 255)
screen.Home()
}

robot := gobot.NewRobot("gopigo3lcd",
[]gobot.Connection{raspiAdaptor},
[]gobot.Device{gpg3, screen},
work,
)

robot.Start()
}
34 changes: 34 additions & 0 deletions examples/gopigo3_grove_light_sensor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// +build example
//
// Do not build by default.

package main

import (
"fmt"

"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/aio"
"gobot.io/x/gobot/platforms/dexter/gopigo3"
"gobot.io/x/gobot/platforms/raspi"
)

func main() {
raspiAdaptor := raspi.NewAdaptor()
gpg3 := gopigo3.NewDriver(raspiAdaptor)
sensor := aio.NewGroveLightSensorDriver(gpg3, "AD_1_1")

work := func() {
sensor.On(sensor.Event("data"), func(data interface{}) {
fmt.Println("sensor", data)
})
}

robot := gobot.NewRobot("gopigo3sensor",
[]gobot.Connection{raspiAdaptor},
[]gobot.Device{gpg3, sensor},
work,
)

robot.Start()
}
41 changes: 41 additions & 0 deletions examples/gopigo3_led_brightness.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// +build example
//
// Do not build by default.

package main

import (
"time"

"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/dexter/gopigo3"
"gobot.io/x/gobot/platforms/raspi"
)

func main() {
raspiAdaptor := raspi.NewAdaptor()
gpg3 := gopigo3.NewDriver(raspiAdaptor)
led := gpio.NewGroveLedDriver(gpg3, "AD_1_1")

work := func() {
brightness := uint8(0)
fadeAmount := uint8(15)

gobot.Every(100*time.Millisecond, func() {
led.Brightness(brightness)
brightness = brightness + fadeAmount
if brightness == 0 || brightness == 255 {
fadeAmount = -fadeAmount
}
})
}

robot := gobot.NewRobot("gopigo3pwm",
[]gobot.Connection{raspiAdaptor},
[]gobot.Device{gpg3, led},
work,
)

robot.Start()
}
38 changes: 38 additions & 0 deletions examples/gopigo3_servo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// +build example
//
// Do not build by default.

package main

import (
"fmt"
"time"

"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/dexter/gopigo3"
"gobot.io/x/gobot/platforms/raspi"
)

func main() {
raspiAdaptor := raspi.NewAdaptor()
gpg3 := gopigo3.NewDriver(raspiAdaptor)
servo := gpio.NewServoDriver(gpg3, "SERVO_1")

work := func() {
gobot.Every(1*time.Second, func() {
i := uint8(gobot.Rand(180))
fmt.Println("Turning", i)
servo.Move(i)
})

}

robot := gobot.NewRobot("gopigo3servo",
[]gobot.Connection{raspiAdaptor},
[]gobot.Device{gpg3, servo},
work,
)

robot.Start()
}
Loading

0 comments on commit 6fbf176

Please sign in to comment.