GithubHelp home page GithubHelp logo

sparkfun / pxt-moto-bit Goto Github PK

View Code? Open in Web Editor NEW
7.0 32.0 7.0 2.57 MB

MakeCode package for the SparkFun Moto:Bit board - beta

Makefile 2.41% TypeScript 97.59%
pxt makecode-extension sparkfun

pxt-moto-bit's Introduction

Moto:bit

SparkFun Moto:bit

The package adds support for the moto:bit add-on board from SparkFun.

TODO: To use this package, go to https://pxt.microbit.org, click Add package and search for moto-bit.

~ hint

Not currently integrated into pxt. It must be manually added. This package is still under development and subject to changes.

~

Usage

The package adds support for the moto:bit add-on board from SparkFun.

Micro:bit Pins Used

The following micro:bit pins are used for analog and digital sensors, motor driving:

  • P0 -- Analog Input 0
  • P1 -- Analog Input 1
  • P2 -- Analog Input 2
  • P8 -- Digital Input/Output
  • P12 -- Digital Input/Output
  • P14 -- Digital Input/Output
  • P15 -- Servo Motor
  • P16 -- Servo Motor
  • P19 -- motor driver - SCL
  • P20 -- motor driver - SDA

Set Motor Speed

To set the speed and direction for a motor, place the |set motor| block. The block takes three parameters: motor select, direction, and speed.

  • The motor select must be either Left or Right
  • Direction must be either Forward or Reverse
  • Speed is an integer value between 0 and 100
motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 50)

Invert Motor Directon

When a motor turns opposite to the direction that was declared, the invert block may be used. The block accepts two parameters: motor select, and a boolean variable. When the boolean is set to true, the motor direction is inverted so that Forward no longer causes the motor to spin in Reverse, but rather Forward.

  • The motor select must be either Left or Right
  • Invert must be either true or false
motobit.invert(Motor.Left, true)

Enabling Motors

Regardless of the set motor speed, before the motors will turn on the switch on moto:bit must be set to "Run Motors", and the enable motors command must be set to ON

  • Motor enable must be either On or Off.
motobit.enable(MotorPower.On)

Examples

Example: Receiving a packet of data over wireless

The following program reads a string to control the direction of two motors.

radio.onDataPacketReceived( ({ receivedNumber }) =>  {
    // Drive forward
    if (receivedNumber == 128) {
        led.plot(2, 0)
        motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 50)
        motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 50)
        motobit.enable(MotorPower.On)
    } else {
        led.unplot(2, 0)
    }
    // Turn left
    if (receivedNumber == 64) {
        led.plot(0, 2)
        motobit.setMotorSpeed(Motor.Left, MotorDirection.Reverse, 50)
        motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 50)
        motobit.enable(MotorPower.On)
    } else {
        led.unplot(0, 2)
    }
    // Turn right
    if (receivedNumber == 32) {
        led.plot(4, 2)
        motobit.setMotorSpeed(Motor.Left, MotorDirection.Forward, 50)
        motobit.setMotorSpeed(Motor.Right, MotorDirection.Reverse, 50)
        motobit.enable(MotorPower.On)
    } else {
        led.unplot(4, 2)
    }
    // Drive in reverse
    if (receivedNumber == 16) {
        led.plot(2, 4)
        motobit.setMotorSpeed(Motor.Left, MotorDirection.Reverse, 50)
        motobit.setMotorSpeed(Motor.Right, MotorDirection.Reverse, 50)
        motobit.enable(MotorPower.On)
    } else {
        led.unplot(2, 4)
    }
    // Stop
    if (receivedNumber == 0) {
        motobit.enable(MotorPower.Off)
    }
})
radio.setGroup(13)

License

MIT

Supported targets

  • for PXT/microbit
motobit=github:sparkfun/pxt-moto-bit

pxt-moto-bit's People

Contributors

andyengland521 avatar awende avatar pelikhan avatar soubsoub avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pxt-moto-bit's Issues

can't control motors independently

The code below causes BOTH left and right motors to spin. Switching to LEFT produces the same result. It seems that whichever motor I select, both motors spin.

`input.onButtonPressed(Button.A, function () {
motobit.enable(MotorPower.On)
motobit.setMotorSpeed(Motor.Right, MotorDirection.Forward, 50)
basic.pause(2000)
motobit.enable(MotorPower.Off)
})
basic.forever(function () {

})`

Description error

Error in the description, it says "... weather:bit board...", but It should say "... moto:bit board...".

Add release

Please use pxt bump to create a release for this package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.