package
1.13.0
Repository: https://github.com/danielfallon/gobot.git
Documentation: pkg.go.dev

# 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()
}

# Functions

NewAdaptor returns a new MegaPi Adaptor with specified serial port used to talk to the MegaPi with a baud rate of 115200.
NewMotorDriver creates a new MotorDriver at the given port.

# Structs

Adaptor is the Gobot adaptor for the MakeBlock MegaPi board.
MotorDriver represents a motor.