megapi

package
v2.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

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

Please refer to the main README.md

How to Use

package main

import (
  "fmt"
  "time"

  "gobot.io/x/gobot/v2"
  "gobot.io/x/gobot/v2/drivers/serial/megapi"
  "gobot.io/x/gobot/v2/platforms/serialport"
)

func main() {
  // use "/dev/ttyUSB0" if connecting with USB cable
  // use "/dev/ttyAMA0" on devices older than Raspberry Pi 3 Model B
  adaptor := serialport.NewAdaptor("/dev/ttyS0", serialport.WithName("MegaPi"))
  motor := megapi.NewMotorDriver(adaptor, 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{adaptor},
    []gobot.Device{motor},
    work,
  )

  if err := robot.Start(); err != nil {
    panic(err)
  }
}

Documentation

Overview

Package megapi provides the Gobot adaptor for MegaPi.

For more information refer to the README: https://github.com/hybridgroup/gobot/blob/release/platforms/megapi/README.md

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL