Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
zhang-tang committed Dec 25, 2024
1 parent 859cb92 commit 1e41381
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 15 deletions.
136 changes: 130 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,140 @@
# Creative Robotics Kit for micro:bit
[Creative Robotics Kit for micro:bit is a robotics platform based on the micro:bit controller, which includes a desktop robot chassis, a micro:bit extension board, servos, line-following sensors, ultrasonic sensors, and other components. The accompanying top plate is directly compatible with 9-gram servos and is equipped with mounting holes for ultrasonic sensors as well as the extension board and sensors, making it convenient for quick installation of various sensors.](https://www.dfrobot.com/)

The Creative Robotics Kit for micro:bit is a robot platform based on the micro:bit controller. It includes a desktop robot chassis, a micro:bit expansion board, servos, a line-tracking sensor, an ultrasonic sensor, and other components. The accompanying top plate is directly compatible with 9g servos and is equipped with mounting holes for ultrasonic sensors, the expansion board, and other sensors, allowing for quick installation of various sensors.

The platform's IO expansion board provides 10 digital/analog 3-pin interfaces and 3 I2C interfaces, enabling easy expansion and control of a wide range of devices. The expansion board features a built-in dual motor driver, eliminating the need to use additional pins. Furthermore, the expansion board exposes the micro:bit edge connector pins (0, 1, 2, 3V, GND), offering developers more interface options.

[]()

[Module Document Address]()

## Basic usage
1. Set the direction and speed of motors connected to M1 and M2 ports.

```blocks
basic.forever(function () {
robotics.motorRun(robotics.MotorType.M1, robotics.MotorDirection.CW, 100)
robotics.motorRun(robotics.MotorType.M2, robotics.MotorDirection.CCW, 100)
})
```
2. Stop all motors.
```blocks
basic.forever(function () {
robotics.motorStop(robotics.MotorType.All)
})
```
3. Initialize the 180° servo motor to 0 degrees, then rotate it to the 90-degree position.
```blocks
robotics.servoRun180(robotics.CustomAllPin.P0, 0)
basic.forever(function () {
robotics.servoRun180(robotics.CustomAllPin.P0, 90)
})
```
4. Control the speed of a 360° servo motor: First, make the servo connected to port P0 rotate forward at 50% speed for 1 second, then reverse for 1 second.
```blocks
basic.forever(function () {
robotics.servoRun360(robotics.CustomAllPin.P0, 50, robotics.MotorDirection.CW)
basic.pause(1000)
robotics.servoRun360(robotics.CustomAllPin.P0, 50, robotics.MotorDirection.CCW)
basic.pause(1000)
})
```
5. Acquire distance data measured by the ultrasonic sensor and send the measurement results via the serial port every 500 milliseconds.
```blocks
basic.forever(function () {
serial.writeLine("" + (robotics.readUltrasonicData(robotics.CustomAllPin.P0)))
basic.pause(500)
})
```
6. Acquire data collected by the line-tracking sensor and send the sensor data via the serial port every 1000 milliseconds.
```blocks
basic.forever(function () {
serial.writeLine("" + (robotics.readLineTrackingData(robotics.CustomAllPin.P0)))
basic.pause(1000)
})
```
7. Acquire data collected by the soil moisture sensor and send the moisture value via the serial port every 1000 milliseconds.
```blocks
basic.forever(function () {
serial.writeLine("" + (robotics.readMoistureData(robotics.CustomAnalogPin.P0)))
basic.pause(1000)
})
```
8. Acquire temperature and humidity data collected by the DHT11 sensor and send the temperature and humidity values via the serial port every 1000 milliseconds.
```blocks
basic.forever(function () {
serial.writeLine("" + (robotics.readDht11Data(robotics.CustomAllPin.P0, robotics.DataType.TemperatureC)))
basic.pause(1000)
})
```
9. Retrieve the data collected by the ambient light sensor and send the light value via serial port every 1000 milliseconds.
### Motor
```blocks
basic.forever(function () {
serial.writeLine("" + (robotics.readLightData(robotics.CustomAnalogPin.P0)))
basic.pause(1000)
})
```
10. Retrieve the data collected by the human infrared sensor and send the collected value via serial port every 1000 milliseconds.
### Servo
```blocks
basic.forever(function () {
serial.writeLine("" + (robotics.readInfraredData(robotics.CustomAllPin.P0)))
basic.pause(1000)
})
```
11. Initialize the RGB LED strip and set the brightness to 200. Then, make the strip display green, which will last for 5 seconds before turning off the LED strip.
### Sensor
```blocks
robotics.ws2812Init(robotics.CustomAllPin.P0, 7)
robotics.ws2812SBrightness(200)
robotics.ws2812ShowColor(0x00ff00)
basic.pause(5000)
robotics.ws2812Off()
```
12. Initialize the RGB LED strip, making the 1st and 2nd LEDs display red, the 3rd and 4th LEDs display green, and the 5th, 6th, and 7th LEDs display blue.
```blocks
robotics.ws2812Init(robotics.CustomAllPin.P0, 7)
robotics.ws2812SBrightness(200)
basic.forever(function () {
robotics.ws2812SetIndexColor(robotics.ws2812LedRange(1, 2), 0xFF0000)
robotics.ws2812SetIndexColor(robotics.ws2812LedRange(3, 4), 0x00ff00)
robotics.ws2812SetIndexColor(robotics.ws2812LedRange(5, 7), 0x0000ff)
})
```
13. Initialize the RGB LED strip to display a gradient color effect.
### RGB
```blocks
robotics.ws2812Init(robotics.CustomAllPin.P0, 7)
robotics.ws2812SBrightness(200)
basic.forever(function () {
robotics.ws2812Rainbow(1, 7, 1, 360)
})
```
14. Use the micro:bit A button to control the lighting of the RGB LED strip. Each time button A is pressed, move the LEDs of the strip one position to the right, checking the button status every 100 milliseconds.
## License
```blocks
robotics.ws2812Init(robotics.CustomAllPin.P0, 7)
robotics.ws2812SBrightness(200)
while (true) {
if (input.buttonIsPressed(Button.A)) {
robotics.ws2812Shift(1)
robotics.ws2812SetIndexColor(1, 0xFF0000)
}
basic.pause(100)
}
```

## LIcense

MIT

Expand All @@ -23,4 +144,7 @@ Copyright (c) 2020, microbit/micropython Chinese community

* for PXT/microbit

```package
robotics=github:DFRobot/pxt-DFRobot_creative-robotics-kit
```

2 changes: 1 addition & 1 deletion _locales/zh-cn/robotics-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"robotics.motorRun|block": "电机 %motor ⽅向 %dir 速度 %speed",
"robotics.motorStop|block": "电机停⽌ %motor",
"robotics.servoRun180|block": "设置 %pin 引脚伺服舵机为 %degree=protractorPicker 度",
"robotics.servoRun360|block": "设置引脚 %pin 以 %speed \\%的速度 %dir",
"robotics.servoRun360|block": "设置引脚 $pin 以 $speed \\%的速度 $dir",
"robotics.readUltrasonicData|block": "获取 %pin 引脚超声波距离 单位(cm)",
"robotics.readLineTrackingData|block": "读取巡线传感器 %pin 状态",
"robotics.readMoistureData|block": "读取引脚 %pin ⼟壤湿度",
Expand Down
10 changes: 5 additions & 5 deletions robotics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ namespace robotics {
}

/**
* Set the speed of motors M1 and M2, they can be set individually or together.
* Set the speed of Motors M1 and M2, they can be set individually or together.
* @param motor to motor, eg: MotorType.M1
* @param dir to dir, eg: MotorDirection.CW
* @param speed to speed, eg: 100
*/
//% block="motor %motor dir %dir speed %speed"
//% block="Motor %motor dir %dir speed %speed"
//% group="Motor"
//% speed.min=0 speed.max=255
//% weight=100
Expand All @@ -112,10 +112,10 @@ namespace robotics {
}

/**
* Stop motors M1 and M2, they can be set individually or together.
* Stop Motors M1 and M2, they can be set individually or together.
* @param motor to motor, eg: MotorType.M1
*/
//% block="motor stop %motor"
//% block="Motor stop %motor"
//% group="Motor"
//% weight=95
export function motorStop(motor: MotorType): void {
Expand Down Expand Up @@ -145,7 +145,7 @@ namespace robotics {
* @param speed to speed, eg: 50
* @param dir to dir, eg: MotorDirection.CW
*/
//% block="pin %pin servo rotate at %speed \\% speed %dir"
//% block="pin $pin servo rotate $dir at $speed \\% speed"
//% group="Servo"
//% speed.min=0 speed.max=100
//% weight=85
Expand Down
6 changes: 3 additions & 3 deletions shims.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@



//% color=50 weight=80
//% icon="\uf1eb"
//% color=50 weight=80
//% icon="\uf1eb"
declare namespace i2c {
}

// Auto-generated. Do not edit. Really.
// Auto-generated. Do not edit. Really.

0 comments on commit 1e41381

Please sign in to comment.