hybridgroup.gobot/platforms/megapi
Thomas Kohler f5d8d5c601
all(style) : fix linter issues for errcheck, ineffassign, unused and fix errors (#950)
2023-06-12 19:51:25 +02:00
..
README.md core(build): CLI removed (#946) 2023-06-04 18:36:55 +02:00
doc.go Build(v2): revert move to v2 subfolder (#932) 2023-05-29 19:23:28 +02:00
megapi_adaptor.go all(style) : fix linter issues for errcheck, ineffassign, unused and fix errors (#950) 2023-06-12 19:51:25 +02:00
motor_driver.go all(style) : fix linter issues for errcheck, ineffassign, unused and fix errors (#950) 2023-06-12 19:51:25 +02: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

Please refer to the main README.md

How to Use

package main

import (
  "gobot.io/x/gobot/v2"
  "gobot.io/x/gobot/v2/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()
}