Add edison grove examples
This commit is contained in:
parent
317591bc39
commit
d751445cc0
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/i2c"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
board := edison.NewEdisonAdaptor("edison")
|
||||
accel := i2c.NewGroveAccelerometerDriver(board, "accel")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(500*time.Millisecond, func() {
|
||||
if x, y, z, err := accel.XYZ(); err == nil {
|
||||
fmt.Println(x, y, z)
|
||||
fmt.Println(accel.Acceleration(x, y, z))
|
||||
} else {
|
||||
fmt.Println(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("accelBot",
|
||||
[]gobot.Connection{board},
|
||||
[]gobot.Device{accel},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
e := edison.NewEdisonAdaptor("edison")
|
||||
led := gpio.NewLedDriver(e, "led", "13")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("blinkBot",
|
||||
[]gobot.Connection{e},
|
||||
[]gobot.Device{led},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
e := edison.NewEdisonAdaptor("edison")
|
||||
button := gpio.NewGroveButtonDriver(e, "button", "2")
|
||||
|
||||
work := func() {
|
||||
gobot.On(button.Event(gpio.Push), func(data interface{}) {
|
||||
fmt.Println("On!")
|
||||
})
|
||||
|
||||
gobot.On(button.Event(gpio.Release), func(data interface{}) {
|
||||
fmt.Println("Off!")
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("bot",
|
||||
[]gobot.Connection{e},
|
||||
[]gobot.Device{button},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
board := edison.NewEdisonAdaptor("edison")
|
||||
buzzer := gpio.NewBuzzerDriver(board, "buzzer", "3")
|
||||
|
||||
work := func() {
|
||||
type note struct {
|
||||
tone float64
|
||||
duration float64
|
||||
}
|
||||
|
||||
song := []note{
|
||||
{gpio.C4, gpio.Quarter},
|
||||
{gpio.C4, gpio.Quarter},
|
||||
{gpio.G4, gpio.Quarter},
|
||||
{gpio.G4, gpio.Quarter},
|
||||
{gpio.A4, gpio.Quarter},
|
||||
{gpio.A4, gpio.Quarter},
|
||||
{gpio.G4, gpio.Half},
|
||||
{gpio.F4, gpio.Quarter},
|
||||
{gpio.F4, gpio.Quarter},
|
||||
{gpio.E4, gpio.Quarter},
|
||||
{gpio.E4, gpio.Quarter},
|
||||
{gpio.D4, gpio.Quarter},
|
||||
{gpio.D4, gpio.Quarter},
|
||||
{gpio.C4, gpio.Half},
|
||||
}
|
||||
|
||||
for _, val := range song {
|
||||
buzzer.Tone(val.tone, val.duration)
|
||||
<-time.After(10 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("bot",
|
||||
[]gobot.Connection{board},
|
||||
[]gobot.Device{buzzer},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/i2c"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
board := edison.NewEdisonAdaptor("edison")
|
||||
screen := i2c.NewGroveLcdDriver(board, "screen")
|
||||
|
||||
work := func() {
|
||||
screen.Write("hello")
|
||||
|
||||
screen.SetRGB(255, 0, 0)
|
||||
|
||||
gobot.After(5*time.Second, func() {
|
||||
screen.Clear()
|
||||
screen.Home()
|
||||
screen.SetRGB(0, 255, 0)
|
||||
screen.Write("goodbye")
|
||||
})
|
||||
|
||||
screen.Home()
|
||||
<-time.After(1 * time.Second)
|
||||
screen.SetRGB(0, 0, 255)
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("screenBot",
|
||||
[]gobot.Connection{board},
|
||||
[]gobot.Device{screen},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
e := edison.NewEdisonAdaptor("edison")
|
||||
led := gpio.NewGroveLedDriver(e, "led", "4")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(1*time.Second, func() {
|
||||
led.Toggle()
|
||||
})
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("blinkBot",
|
||||
[]gobot.Connection{e},
|
||||
[]gobot.Device{led},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
board := edison.NewEdisonAdaptor("board")
|
||||
sensor := gpio.NewGroveLightSensorDriver(board, "sensor", "0")
|
||||
|
||||
work := func() {
|
||||
gobot.On(sensor.Event("data"), func(data interface{}) {
|
||||
fmt.Println("sensor", data)
|
||||
})
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("sensorBot",
|
||||
[]gobot.Connection{board},
|
||||
[]gobot.Device{sensor},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
board := edison.NewEdisonAdaptor("edison")
|
||||
sensor := gpio.NewGrovePiezoVibrationSensorDriver(board, "sensor", "0")
|
||||
|
||||
work := func() {
|
||||
gobot.On(sensor.Event(gpio.Vibration), func(data interface{}) {
|
||||
fmt.Println("got one!")
|
||||
})
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("bot",
|
||||
[]gobot.Connection{board},
|
||||
[]gobot.Device{sensor},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
board := edison.NewEdisonAdaptor("board")
|
||||
sensor := gpio.NewGroveRotaryDriver(board, "sensor", "0")
|
||||
|
||||
work := func() {
|
||||
gobot.On(sensor.Event("data"), func(data interface{}) {
|
||||
fmt.Println("sensor", data)
|
||||
})
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("sensorBot",
|
||||
[]gobot.Connection{board},
|
||||
[]gobot.Device{sensor},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
board := edison.NewEdisonAdaptor("board")
|
||||
sensor := gpio.NewGroveSoundSensorDriver(board, "sensor", "0")
|
||||
|
||||
work := func() {
|
||||
gobot.On(sensor.Event("data"), func(data interface{}) {
|
||||
fmt.Println("sensor", data)
|
||||
})
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("sensorBot",
|
||||
[]gobot.Connection{board},
|
||||
[]gobot.Device{sensor},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
board := edison.NewEdisonAdaptor("board")
|
||||
sensor := gpio.NewGroveTemperatureSensorDriver(board, "sensor", "0")
|
||||
|
||||
work := func() {
|
||||
gobot.Every(500*time.Millisecond, func() {
|
||||
fmt.Println("current temp (c): ", sensor.Temperature())
|
||||
})
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("sensorBot",
|
||||
[]gobot.Connection{board},
|
||||
[]gobot.Device{sensor},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hybridgroup/gobot"
|
||||
"github.com/hybridgroup/gobot/platforms/gpio"
|
||||
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||||
)
|
||||
|
||||
func main() {
|
||||
gbot := gobot.NewGobot()
|
||||
|
||||
e := edison.NewEdisonAdaptor("edison")
|
||||
touch := gpio.NewGroveTouchDriver(e, "touch", "2")
|
||||
|
||||
work := func() {
|
||||
gobot.On(touch.Event(gpio.Push), func(data interface{}) {
|
||||
fmt.Println("On!")
|
||||
})
|
||||
|
||||
gobot.On(touch.Event(gpio.Release), func(data interface{}) {
|
||||
fmt.Println("Off!")
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
robot := gobot.NewRobot("blinkBot",
|
||||
[]gobot.Connection{e},
|
||||
[]gobot.Device{touch},
|
||||
work,
|
||||
)
|
||||
|
||||
gbot.AddRobot(robot)
|
||||
|
||||
gbot.Start()
|
||||
}
|
Loading…
Reference in New Issue