hybridgroup.gobot/platforms/megapi
Marc-Antoine Ruel 88addd428f Add crude travis check for gofmt; format all sources
The check ensures no gofmt regression occurs. Formatting the code makes everyone happy.
2017-03-27 14:10:37 -04:00
..
README.md core: use canonical import domain of gobot.io for all code 2016-12-08 13:24:03 +01:00
doc.go docs: correct MegaPi README link 2016-12-21 10:53:31 +01:00
megapi_adaptor.go Add crude travis check for gofmt; format all sources 2017-03-27 14:10:37 -04:00
motor_driver.go core: use canonical import domain of gobot.io for all code 2016-12-08 13:24:03 +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 gobot.io/x/gobot/... && go install gobot.io/x/gobot/platforms/megapi

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