View on GitHub

pxt-rekabit-rbt-project-kit

Cytron REKA:BIT RBT Project Kit Extension for MakeCode

REKA:BIT RBT Project Kit Extension for Microsoft MakeCode

This code provides the MakeCode blocks for REKA:BIT RBT Project Kit with the aim to lower the learning curve for beginners who wants to build STEAM (and RBT) projects with micro:bit.

REKA:BIT RBT Project Kit

This project kit utilizes REKA:BIT which expands the capabilities of the feature-packed micro:bit in robotics :robot: applications. With the built-in 2-channel DC motor driver, 4x servo control and external power input DC jack, anyone can build projects with mechanical movements right away. The Grove ports enable additional sensors and modules to be connected conveniently. The LED status indicators on its IO pins provides hassleless code & wiring troubleshooting. REKA:BIT works with micro:bit V1 & V2.

Adding the Extension in MakeCode Editor

Examples

REKA:BIT DC Motors

Run Motor 1 forward at 50% speed when button A is pressed, brake the motor when button B is pressed.

input.onButtonPressed(Button.A, function () {
    rekabit.runMotor(MotorChannel.M1, MotorDirection.Forward, 127)
})
input.onButtonPressed(Button.B, function () {
    rekabit.brakeMotor(MotorChannel.M1)
})

REKA:BIT Servos

Button A pressed - Rotate Servo 1 to 0 degree. Button B pressed - Rotate Servo 1 to 180 degree. Button A+B pressed - Disable Servo 1. No pulse is sent to Servo 1 and it can be rotated by hand.

input.onButtonPressed(Button.A, function () {
    rekabit.setServoPosition(ServoChannel.S1, 0)
})
input.onButtonPressed(Button.B, function () {
    rekabit.setServoPosition(ServoChannel.S1, 180)
})
input.onButtonPressed(Button.AB, function () {
    rekabit.disableServo(ServoChannel.S1)
})

RGB Stick

Initialize RGB Stick and assign micro:bit pin P0 to it.

:point_down: This code must be added at the beginning of each project that uses RGB Stick.

rekabitRgbStick.create(RekabitPortYellowPin.P0)

Turn off the RGB Stick.

rekabitRgbStick.create(RekabitPortYellowPin.P0)
rekabitRgbStick.turnoff()

Change the RGB Stick brightness to maximum.

rekabitRgbStick.create(RekabitPortYellowPin.P0)
rekabitRgbStick.setBrightness(255)

Show RGB Stick to green color on all the pixels and change the color one by one to red.

rekabitRgbStick.create(RekabitPortYellowPin.P0)
rekabitRgbStick.showColor(0x00ff00)
basic.pause(1000)
for (let index = 0; index <= 7; index++) {
    rekabitRgbStick.setPixelColor(index, 0xff0000)
    basic.pause(500)
}

Big LEDs

Set Big LED at pin P13 to On.

rekabitBigLED.setBigLed(RekabitPortYellowPin.P13, rekabitBigLED.digitalStatePicker(RekabitDigitalIoState.On))

Toggle Big LED at pin P13 for 4 times. The LED will turn on if its previous state is off, and vice versa.

for (let index = 0; index < 4; index++) {
    rekabitBigLED.toggleBigLed(RekabitPortYellowPin.P13)
    basic.pause(1000)
}

Soil Moisture Sensor

Compare soil moisture level, show :heavy_check_mark: if less than 550 (moist) or show :x: if more than 550 (dry).

basic.forever(function () {
    if (rekabitSoilMoisture.compareAnalog(RekabitAnalogInPin.P2, RekabitAnalogCompareType.LessThan, 550)) {
        basic.showIcon(IconNames.Yes)
    } else {
        basic.showIcon(IconNames.No)
    }
})

Ultrasonic Sensor

Initialize Ultrasonic sensor and assign micro:bit pins:

rekabitUltrasonic.setUltrasonicTrigEcho(RekabitUltrasonicIOPins.p2_p12)

Compare ultrasonic distance in cm, show :heart: if less than 20cm or show :smiley: if more than 20cm.

rekabitUltrasonic.setUltrasonicTrigEcho(RekabitUltrasonicIOPins.p2_p12)
basic.forever(function () {
    if (rekabitUltrasonic.compareDistance(RekabitAnalogCompareType.LessThan, 20)) {
        basic.showIcon(IconNames.Heart)
    } else {
        basic.showIcon(IconNames.Happy)
    }
})

License

MIT

Supported targets

Open this page at https://cytrontechnologies.github.io/pxt-rekabit-rbt-project-kit/