hybridgroup.gobot/platforms/megapi
deadprogram 5dff2aa169 core: update Megapi platform to simply return error
Signed-off-by: deadprogram <ron@hybridgroup.com>
2016-11-07 21:29:52 +01:00
..
README.md docs: remove Master unless needed for less code 2016-10-18 21:37:10 +02:00
megapi_adaptor.go core: update Megapi platform to simply return error 2016-11-07 21:29:52 +01:00
motor_driver.go core: update Megapi platform to simply return error 2016-11-07 21:29:52 +01:00

README.md

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 github.com/hybridgroup/gobot/... && go install github.com/hybridgroup/gobot/platforms/megapi

How to Use

package main

import (
	"github.com/hybridgroup/gobot"
	"github.com/hybridgroup/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()
}