README ¶
MegaPi
The MegaPi is a motor controller by MakeBlock that is compatible with the Raspberry Pi.
The code is based on a python implementation that can be found here.
How to Install
go get -d -u gobot.io/x/gobot/...
How to Use
package main
import (
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/megapi"
"time"
)
func main() {
// use "/dev/ttyUSB0" if connecting with USB cable
// use "/dev/ttyAMA0" on devices older than Raspberry Pi 3 Model B
megaPiAdaptor := megapi.NewAdaptor("/dev/ttyS0")
motor := megapi.NewMotorDriver(megaPiAdaptor, 1)
work := func() {
speed := int16(0)
fadeAmount := int16(30)
gobot.Every(100*time.Millisecond, func() {
motor.Speed(speed)
speed = speed + fadeAmount
if speed == 0 || speed == 300 {
fadeAmount = -fadeAmount
}
})
}
robot := gobot.NewRobot("megaPiBot",
[]gobot.Connection{megaPiAdaptor},
[]gobot.Device{motor},
work,
)
robot.Start()
}
Documentation ¶
Overview ¶
Package megapi provides the Gobot adaptor for MegaPi.
For more information refer to the README: https://github.com/hybridgroup/gobot/blob/master/platforms/megapi/README.md
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adaptor ¶ added in v1.0.0
type Adaptor struct {
// contains filtered or unexported fields
}
Adaptor is the Gobot adaptor for the MakeBlock MegaPi board
func NewAdaptor ¶ added in v1.0.0
NewAdaptor returns a new MegaPi Adaptor with specified serial port used to talk to the MegaPi with a baud rate of 115200
type MotorDriver ¶
type MotorDriver struct {
// contains filtered or unexported fields
}
MotorDriver represents a motor
func NewMotorDriver ¶
func NewMotorDriver(megaPi *Adaptor, port byte) *MotorDriver
NewMotorDriver creates a new MotorDriver at the given port
func (*MotorDriver) Connection ¶
func (m *MotorDriver) Connection() gobot.Connection
Connection returns the Connection associated with the Driver
func (*MotorDriver) SetName ¶ added in v1.0.0
func (m *MotorDriver) SetName(n string)
SetName sets the name of this motor
func (*MotorDriver) Speed ¶
func (m *MotorDriver) Speed(speed int16) error
Speed sets the motors speed to the specified value
func (*MotorDriver) Start ¶
func (m *MotorDriver) Start() error
Start implements the Driver interface