Skip to content

Instantly share code, notes, and snippets.

@michaelbernstein
Forked from zankich/01-getting_started.md
Last active August 29, 2015 14:24
Show Gist options
  • Save michaelbernstein/1c7efc093e7fffdc4aff to your computer and use it in GitHub Desktop.
Save michaelbernstein/1c7efc093e7fffdc4aff to your computer and use it in GitHub Desktop.
// Open the seed studio grove kit box and find the little green bag labeled "Grove - 3-axis Digital Accelerometer", open the
// bag and plug the grove connector cable into the grove slot labeled "I2C".
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()
}
// Open the seed studio grove kit box and find the little green bag labeled "Grove - Button", open the bag and plug the grove
// connector cable into the grove slot labeled "D2".
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()
}
// Open the seed studio grove kit box and find the little green bag labeled "Grove - Buzzer", open the bag and plug the grove
// connector cable into the grove slot labeled "D3".
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()
}
// Open the seed studio grove kit box and find the little green bag labeled "Grove - LCD", open the
// bag and plug the grove connector cable into the grove slot labeled "I2C".
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()
}
// Open the seed studio grove kit box and find the little green bag labeled "Grove - Blue LED", open the bag and plug the grove
// connector cable into the grove slot labeled "D4". When installing the LED into the grove connector, be sure to plug the longer
// LED lead into the "+" and the shorter lead into the "-".
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()
}
// Open the seed studio grove kit box and find the little green bag labeled "Grove - Light Sensor", open the
// bag and plug the grove connector cable into the grove slot labeled "A0".
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()
}
// Open the seed studio grove kit box and find the little green bag labeled "Grove - Piezo Vibration Sensor", open the
// bag and plug the grove connector cable into the grove slot labeled "A0".
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()
}
// Open the seed studio grove kit box and find the little green bag labeled "Grove - Rotary Angle Sensor", open the
// bag and plug the grove connector cable into the grove slot labeled "A0".
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()
}
// Open the seed studio grove kit box and find the little green bag labeled "Grove - Sound Sensor", open the
// bag and plug the grove connector cable into the grove slot labeled "A0".
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()
}
// Open the seed studio grove kit box and find the little green bag labeled "Grove - Temperature sensor", open the
// bag and plug the grove connector cable into the grove slot labeled "A0".
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()
}
// Open the seed studio grove kit box and find the little green bag labeled "Grove - Touch Sensor", open the
// bag and plug the grove connector cable into the grove slot labeled "D2".
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()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment