Skip to content

Commit

Permalink
耳洞超声波针对microbit版本调整返回值/增加毫米单位选项
Browse files Browse the repository at this point in the history
  • Loading branch information
hogan96 committed May 10, 2023
1 parent 5aa62b0 commit 7cafe48
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 35 deletions.
87 changes: 59 additions & 28 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,67 @@

// A task runner that calls the PXT compiler and
{
"version": "0.1.0",
"version": "2.0.0",

// The command is pxt. Assumes that PXT has been installed using npm install -g pxt
"command": "pxt",

// The command is a shell script
"isShellCommand": true,

// Show the output window always.
"showOutput": "always",

"tasks": [{
"taskName": "deploy",
"isBuildCommand": true,
"problemMatcher": "$tsc",
"args": [""]
}, {
"taskName": "build",
"isTestCommand": true,
"problemMatcher": "$tsc",
"args": [""]
}, {
"taskName": "clean",
"isTestCommand": true,
"problemMatcher": "$tsc",
"args": [""]
}, {
"taskName": "serial",
"isTestCommand": true,
"problemMatcher": "$tsc",
"args": [""]
}]
"tasks": [
{
"label": "deploy",
"type": "shell",
"command": "pxt",
"args": [
"deploy",
""
],
"problemMatcher": "$tsc",
"group": {
"_id": "build",
"isDefault": false
}
},
{
"label": "build",
"type": "shell",
"command": "pxt",
"args": [
"build",
""
],
"problemMatcher": "$tsc",
"group": {
"_id": "test",
"isDefault": false
}
},
{
"label": "clean",
"type": "shell",
"command": "pxt",
"args": [
"clean",
""
],
"problemMatcher": "$tsc",
"group": {
"_id": "test",
"isDefault": false
}
},
{
"label": "serial",
"type": "shell",
"command": "pxt",
"args": [
"serial",
""
],
"problemMatcher": "$tsc",
"group": {
"_id": "test",
"isDefault": false
}
}
]
}
36 changes: 36 additions & 0 deletions .vscode/tasks.json.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

// A task runner that calls the PXT compiler and
{
"version": "0.1.0",

// The command is pxt. Assumes that PXT has been installed using npm install -g pxt
"command": "pxt",

// The command is a shell script
"isShellCommand": true,

// Show the output window always.
"showOutput": "always",

"tasks": [{
"taskName": "deploy",
"isBuildCommand": true,
"problemMatcher": "$tsc",
"args": [""]
}, {
"taskName": "build",
"isTestCommand": true,
"problemMatcher": "$tsc",
"args": [""]
}, {
"taskName": "clean",
"isTestCommand": true,
"problemMatcher": "$tsc",
"args": [""]
}, {
"taskName": "serial",
"isTestCommand": true,
"problemMatcher": "$tsc",
"args": [""]
}]
}
5 changes: 4 additions & 1 deletion _locales/zh-cn/robotbit-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
"robotbit.MotorStop|block": "电机 停止|%index|",
"robotbit.MotorStopAll|block": "停止所有电机",
"robotbit.RgbUltrasonic|block": "猫耳RGB超声波|引脚 %pin",
"robotbit.HoleUltrasonic|block": "猫耳洞超声波|引脚 %pin",
"robotbit.HoleUltrasonic|block": "猫耳洞超声波|引脚 %pin|单位 %unit",
"robotbit.MatrixDraw|block": "LED矩阵 描点|X %x|Y %y",
"robotbit.MatrixClear|block": "清空 LED矩阵 ",
"robotbit.MatrixRefresh|block": "刷新 LED矩阵 ",

"robotbit.ValueUnit.Millimeter|block": "毫米",
"robotbit.ValueUnit.Centimeters|block": "厘米",

"{id:group}Servo": "舵机",
"{id:group}Motor": "电机/步进电机",
"{id:group}Modules": "外接模块"
Expand Down
5 changes: 4 additions & 1 deletion _locales/zh-tw/robotbit-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
"robotbit.MotorStop|block": "馬達 停止|%index|",
"robotbit.MotorStopAll|block": "停止所有馬達",
"robotbit.RgbUltrasonic|block": "貓耳RGB超聲波|腳位 %pin",
"robotbit.HoleUltrasonic|block": "貓耳洞超聲波|腳位 %pin",
"robotbit.HoleUltrasonic|block": "貓耳洞超聲波|腳位 %pin|單位 %unit",
"robotbit.MatrixDraw|block": "LED矩陣 描點|X %x|Y %y",
"robotbit.MatrixClear|block": "清空 LED矩陣",

"robotbit.ValueUnit.Millimeter|block": "毫米",
"robotbit.ValueUnit.Centimeters|block": "厘米",

"{id:group}Servo": "舵機",
"{id:group}Motor": "馬達/步進",
"{id:group}Modules": "外部模塊"
Expand Down
26 changes: 23 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ namespace robotbit {
T5B0 = 1800
}

export enum ValueUnit {
//% block="mm"
Millimeter,
//% block="cm"
Centimeters
}

let initialized = false
let initializedMatrix = false
let neoStrip: neopixel.Strip;
Expand Down Expand Up @@ -524,10 +531,12 @@ namespace robotbit {
/**
* signal pin
* @param pin singal pin; eg: DigitalPin.P1
* @param unit desired conversion unit
*/
//% blockId=robotbit_holeultrasonicver block="Ultrasonic(with LEGO Hole)|pin %pin"
//% blockId=robotbit_holeultrasonicver block="Ultrasonic(with LEGO Hole)|pin %pin|unit %unit"
//% group="Modules" weight=40
export function HoleUltrasonic(pin: DigitalPin): number {
export function HoleUltrasonic(pin: DigitalPin, unit: ValueUnit): number {
pins.setPull(pin, PinPullMode.PullNone);
// pins.setPull(pin, PinPullMode.PullDown);
pins.digitalWritePin(pin, 0);
control.waitMicros(2);
Expand All @@ -546,6 +555,17 @@ namespace robotbit {
distanceBuf = d;
pins.digitalWritePin(pin, 0);
basic.pause(15)
return Math.floor(ret / 40 + (ret / 800));
if (parseInt(control.hardwareVersion()) == 2) {
d = ret *10 /58;
}
else{
// return Math.floor(ret / 40 + (ret / 800));
d = ret * 15 / 58;
}
switch (unit) {
case ValueUnit.Millimeter: return Math.floor(d)
case ValueUnit.Centimeters: return Math.floor(d/10)
default: return d;
}
}
}
12 changes: 10 additions & 2 deletions pxt.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "robotbit",
"version": "0.4.4",
"version": "0.4.5",
"description": "Extension for Kittenbot Robotbit",
"license": "MIT",
"dependencies": {
"core": "*",
"neopixel": "github:kittenbot/pxt-neopixel",
"SensorPlus": "github:kittenbothk/pxt-moduleplus"
"SensorPlus": "github:kittenbothk/pxt-moduleplus",
"microphone": "*"
},
"files": [
"README.md",
Expand All @@ -18,5 +19,12 @@
"test.ts"
],
"public": true,
"targetVersions": {
"target": "5.1.26",
"targetId": "microbit"
},
"supportedTargets": [
"microbit"
],
"preferredEditor": "tsprj"
}

0 comments on commit 7cafe48

Please sign in to comment.