View on GitHub

pxt-sumobit

Cytron SUMO:BIT - Sumo Robot Expansion Board for micro:bit

SUMO:BIT Extension for Microsoft MakeCode

This code provides the driver for SUMO:BIT.

SUMO:BIT is a sumo robot expansion board designed for the BBC micro:bit. It emulates the educational focus of the micro:bit and the simplicity of its coding environment to simplify robotic projects, specifically sumo robots.

SUMO:BIT

Adding the Extension in MakeCode Editor

Examples

DC Motors

Moving the robot foward or backward


input.onButtonPressed(Button.A, function () {
    // Both motor move forward at 100 speed and 9 acceleration factor for 1 second
    sumobit.runMotor(SumobitMotorChannel.Both, SumobitMotorDirection.Forward, 100, 9)
    basic.pause(1000) 
    // Stop both motors for 0.2 second
    sumobit.stopMotor(SumobitMotorChannel.Both)
    basic.pause(200)
    // Both motor move backwatd at 100 speed and 9 acceleration factor for 1 second
    sumobit.runMotor(sumobit.MotorChannel.All, MotorDirection.Backward, 100, 0)
    basic.pause(1000)
    // Stop both motors
    sumobit.stopMotor(SumobitMotorChannel.Both)
})

Making a left or right turn


input.onButtonPressed(Button.A, function () {
    // Both motor move forward at 100 speed and 9 acceleration factor for 1 second
    sumobit.runMotor(SumobitMotorChannel.Both, SumobitMotorDirection.Forward, 100, 9)
    basic.pause(1000)
    // Rotate in place by running both motors in opposite directions
    sumobit.setMotorsSpeed(50, -50, 9)
    basic.pause(500)
    // Run both motor at 50 speed and 9 acceleration factor for 0.5 second
    sumobit.runMotor(SumobitMotorChannel.Both, SumobitMotorDirection.Forward, 50, 9)
    basic.pause(500)
    // Rotate around the right wheel by stopping the right motor and running the left motor
    sumobit.setMotorsSpeed(0, 50, 9)
    basic.pause(1000)
    // Run both motor at 50 speed and 9 acceleration factor for 0.8 second
    sumobit.runMotor(SumobitMotorChannel.Both, SumobitMotorDirection.Forward, 100, 9)
    basic.pause(800
    // Stop both motors)
    sumobit.stopMotor(SumobitMotorChannel.Both)
})

RGB

Basic RGB control


basic.forever(function () {
    // Show blue colour on RGB0 LED
    sumobit.setRgbPixelColor(0, 0x0000ff)
    // Show yellow colour on RGB1 LED
    sumobit.setRgbPixelColor(1, 0xffff00)
    basic.pause(2000)
    // Show purple colour on RGB LED pixels
    sumobit.setAllRgbPixelsColor(sumobit.rgb(255, 0, 255))
    basic.pause(2000)
    // Turn off all RGB lights
    sumobit.clearAllRgbPixels()
    basic.pause(2000)
})

Opponent Sensors

Display the opponent sensor state and perform an action when obstacle is detected


basic.forever(function () {
    // LED matrix display the current state of the front center opponent sensor (0 or 1)
    basic.showNumber(sumobit.oppSensorValue(SumobitSensorSelection1.Center))
    // Red RGB will light up if obstacle detacted by the front center opponent sensor
    if (sumobit.oppSensorDetection(SumobitSensorSelection2.Left)) {
        sumobit.setAllRgbPixelsColor(0xff0000)
    } else {
        sumobit.clearAllRgbPixels()
    }
})

Edge Sensor

Read the analog input values of right and left edge sensors


basic.forever(function () {
    serial.writeString("RIGHT EDGE: ")
    serial.writeString("" + (sumobit.fetchEdgeValue(SumobitEdgeSelection.Right)))
    serial.writeString(" | LEFT EDGE: ")
    serial.writeString("" + (sumobit.fetchEdgeValue(SumobitEdgeSelection.Left)))
    serial.writeLine("")
    basic.pause(500)
})


Basic Backoff routine


// Calibrate the edge sensor to find the threshold value
sumobit.calibrateEdgeThreshold()
basic.forever(function () {
    // Check if the sensor reading is less than threshold value (edge detected)
    if (sumobit.compareEdgeCalibrated(SumobitEdgeSelection.Right)) {
        // Reverse the robot to move away from the edge
        sumobit.runMotor(SumobitMotorChannel.Both, SumobitMotorDirection.Backward, 50, 9)
        basic.pause(300)
        // Make a ~180 degree rotation
        sumobit.setMotorsSpeed(-50, 50)
        basic.pause(500)
        // Stop the robot for a while before continue searching for opponent
        sumobit.stopMotor(SumobitMotorChannel.Both)
        basic.pause(50)
    }
})

Mode

Display current mode and perform an action based on selected mode


basic.forever(function () {
    // LED matrix display the current mode
    basic.showNumber(sumobit.readModeValue())
    // Red RGB will light up when the current mode is 7
    if (sumobit.checkMode(7)) {
        sumobit.setAllRgbPixelsColor(0x00ff00)
    } else {
        sumobit.clearAllRgbPixels()
    }
})

Battery

Display battery level and give warning when battery is low


basic.forever(function () {
    // LED matrix diplay the battery voltage
    basic.showNumber(sumobit.readBatteryValue())
    // Red RGB will light up when the battery voltage is less tgab 11V
    if (sumobit.readBatteryValue() < 11) {
        sumobit.setAllRgbPixelsColor(0xff0000)
    } else {
        sumobit.clearAllRgbPixels()
    }
})

More (Robot Kit)