Code Monkey home page Code Monkey logo

pxt-ibit's Introduction

iBIT block package for i-BIT robot kit

powered by micro:bit

i-BIT

The package adds support for the i-BIT conroller board from Innovative Experiment INEX.

micro:bit Pin Assignment

The following micro:bit pins are used for analog and digital sensors, DC motor drivers and servo motors:

  • P0 -- Analog Input 0 (micro:bit default)
  • P1 -- Analog Input 1 (micro:bit default)
  • P2 -- Analog Input 2 (micro:bit default)
  • P8 -- Digital Input/Output and AnalogWrite/Servo1
  • P12 -- Digital Input/Output and AnalogWrite/Servo2
  • P13 -- DigitalWrite Pin for DC motor control direction 1
  • P14 -- AnalogWrite Pin for DC motor speed control 1
  • P15 -- DigitalWrite Pin for DC motor control direction 2
  • P16 -- AnalogWrite Pin for DC motor speed control 2
  • P19 -- SCL connected to I2C-based 12-bit ADC chip (ADS7828)
  • P20 -- SDA connected to I2C-based 12-bit ADC chip (ADS7828)

Motor control Block

Use iBIT's motor block to drives motor forward and backward. The speed motor is adjustable between 0 to 100.

  • The dirrection must be select either Forward or Backward
  • Speed is an integer value between 0 - 100
iBIT.Motor(ibitMotor.Forward, 100)

iBIT.Motor(ibitMotor.Backward, 100)

Spin Block

Spin block is used to control both motors separately. For example, choose one motor spin with forward direction another one spin with backward direction.

  • The Spin select direction must be either Left or Right
  • Speed is an integer value between 0 - 100
iBIT.Spin(ibitSpin.Left, 100)

iBIT.Spin(ibitSpin.Right, 100)

Turn Block

The Turn block is used to to control the robot movment by turning. The one motor will stop, another one is moving. The vipot point is a center of the robot body.

  • The Turn select direction must be either Left or Right
  • Speed is an integer value between 0 - 100
iBIT.Turn(ibitTurn.Left, 100)

iBIT.Turn(ibitTurn.Right, 100)

Motor Stop Block

The Motor Stop block is used to stop both motors. The speed is set to 0 automatic.

iBIT.MotorStop()

Servo Block

Use this block for control the servo's moving degree from 0 to 180

  • Degree is an integer value between 0 - 180
iBIT.Servo(ibitServo.SV1, 90)

ReadAD Block

This block is used to read the analog input data from the I2C-based ADC integrated circuit, ADS7828. The resolution of conversion is 12-bit. Data will be 0 to 4095. iBIT have 8-ch analog inputs. The pinout voltage range is 0 to +3.3V

  • Analog sensor port are ADC0 - ADC7
  • Select analog channel from ADC0 - ADC7 for reading the analog sensor.
  • Get the analog value to set the conditions for the robot's mission.

Example

  • Read the analog input 0 and display the conversion data on micro:bit. User can change the analog channel any time.
basic.showNumber(iBIT.ReadADC(ibitReadADC.ADC0))
  • Drive the motors with Forward and Backward by counting speed 0 - 100
let speed = 0
basic.forever(() => {
    for (let speed = 0; speed <= 100; speed++) {
        iBIT.Motor(ibitMotor.Forward, speed)
        basic.pause(50)
    }
    for (let speed = 0; speed <= 100; speed++) {
        iBIT.Motor(ibitMotor.Backward, speed)
        basic.pause(50)
    }
})
  • Drive the motors by pressing button A and B. Turn Left by speed 50 when pressed button A and Turn Right by speed 50 when pressed button B.
input.onButtonPressed(Button.A, () => {
    iBIT.Turn(ibitTurn.Left, 50)
})
input.onButtonPressed(Button.B, () => {
    iBIT.Turn(ibitTurn.Right, 50)
})
  • Spin the motors by pressing button A and B. Spin Left by speed 50 when pressed button A and Spin Right by speed 50 when pressed button B.
input.onButtonPressed(Button.A, () => {
    iBIT.Spin(ibitSpin.Left, 50)
})
input.onButtonPressed(Button.B, () => {
    iBIT.Spin(ibitSpin.Right, 50)
})
  • Example for Servo, drive the servo motor's movement angle at Servo output 1 and 2 from 0 - 180 and back to 0 to restart again.
basic.forever(() => {
    for (let Degree = 0; Degree <= 180; Degree++) {
        iBIT.Servo(ibitServo.SV1, Degree)
        iBIT.Servo(ibitServo.SV2, Degree)
        basic.pause(10)
        while (Degree == 180) {
            Degree = 0
        }
    }
})
  • Example for set Servo Stop or set freedom servo.
input.onButtonPressed(Button.A, () => {
    iBIT.Servo(ibitServo.SV1, 90)
})
input.onButtonPressed(Button.B, () => {
    iBIT.ServoStop(ibitServo.SV1)
})

License

MIT

Supported targets

  • for PXT/microbit

pxt-ibit's People

Contributors

awiruth250271 avatar emwta avatar kritsadaj avatar pelikhan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pxt-ibit's Issues

Coding guidelines

Could you do some renaming to follow MakeCode naming guidelines:

  • enums: capitalized
  • enum member: capitalized
  • classes: capitalied
  • functions: camelized
  • members of classes: camelized

Enable travis build

  • Add .travis.yml file
language: node_js
node_js:
  - "8.9.4"
script:
  - "npm install -g pxt"
  - "pxt target microbit"
  - "pxt install"
  - "pxt build --cloud"
sudo: false
cache:
  directories:
    - npm_modules
    - pxt_modules

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.