Skip to content

Instantly share code, notes, and snippets.

@gatarelib
Last active March 28, 2022 13:37
Show Gist options
  • Save gatarelib/5e379cd518fd7ac73e69964b8194d144 to your computer and use it in GitHub Desktop.
Save gatarelib/5e379cd518fd7ac73e69964b8194d144 to your computer and use it in GitHub Desktop.
Golang framework for robotics, drones, and the Internet of Things (IoT)
package main
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
)
func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
led := gpio.NewLedDriver(firmataAdaptor, "13")
work := func() {
gobot.Every(1*time.Second, func() {
led.Toggle()
})
}
robot := gobot.NewRobot("bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{led},
work,
)
robot.Start()
}
// +build example
//
// Do not build by default.
package main
import (
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/audio"
)
func main() {
e := audio.NewAdaptor()
laser := audio.NewDriver(e, "./examples/laser.mp3")
work := func() {
gobot.Every(2*time.Second, func() {
laser.Play()
})
}
robot := gobot.NewRobot("soundBot",
[]gobot.Connection{e},
[]gobot.Device{laser},
work,
)
robot.Start()
}
package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/sphero"
)
func main() {
adaptor := sphero.NewAdaptor("/dev/rfcomm0")
driver := sphero.NewSpheroDriver(adaptor)
work := func() {
gobot.Every(3*time.Second, func() {
driver.Roll(30, uint16(gobot.Rand(360)))
})
}
robot := gobot.NewRobot("sphero",
[]gobot.Connection{adaptor},
[]gobot.Device{driver},
work,
)
robot.Start()
}
@gatarelib
Copy link
Author

gatarelib commented Mar 28, 2022

You can use the entire Gobot framework as shown in the examples above, or you can pick and choose from the various Gobot packages to control hardware with nothing but pure idiomatic Golang code.

the audio.go being an impementation example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment