From 58c4e57f81741514710278abfb60801d3a22225c Mon Sep 17 00:00:00 2001 From: tiandiyishaou Date: Tue, 30 Jan 2024 11:49:16 +0800 Subject: [PATCH] =?UTF-8?q?add=20lego=20360=C2=B0=20servo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StartbitV2.ts | 25 +++++++++++++++++++++++++ _locales/zh/StartbitV2-strings.json | 1 + 2 files changed, 26 insertions(+) diff --git a/StartbitV2.ts b/StartbitV2.ts index 96097cc..27ff418 100644 --- a/StartbitV2.ts +++ b/StartbitV2.ts @@ -564,6 +564,31 @@ namespace StartbitV2 { serial.writeBuffer(buf); basic.pause(1); } + + /** + * Set the speed of servo 1 to 6, range of 0~270 degree + */ + //% weight=96 blockId=setLogoServo block="Set logo 360° servo index %index speed %speed" + //% speed.min=-180 speed.max=180 + //% inlineInputMode=inline + //% subcategory=Servo/Motor + export function setLogoServo(index: number = 1, speed: number) { + speed += 180; + let position = mapRGB(speed, 0, 360, 500, 2500); + let buf = pins.createBuffer(10); + buf[0] = 0x55; + buf[1] = 0x55; + buf[2] = 0x08; + buf[3] = 0x03;//cmd type + buf[4] = 0x01; + buf[5] = 100 & 0xff; + buf[6] = (100 >> 8) & 0xff; + buf[7] = index; + buf[8] = position & 0xff; + buf[9] = (position >> 8) & 0xff; + serial.writeBuffer(buf); + basic.pause(1); + } /** * Set the servo controller to run a actiongroup diff --git a/_locales/zh/StartbitV2-strings.json b/_locales/zh/StartbitV2-strings.json index ddba063..8ce47de 100644 --- a/_locales/zh/StartbitV2-strings.json +++ b/_locales/zh/StartbitV2-strings.json @@ -159,6 +159,7 @@ "StartbitV2.setPwmServo|block":"设置PWM舵机|转动范围 %range|编号 %index|角度 %angle|时长 %duration", "StartbitV2.setArrayServo|block":"设置PWM舵机|转动范围 %range|编号(数组类型) %index|角度(数组类型) %angle|时长 %duration", "StartbitV2.setBusServo|block":"设置总线舵机|ID %index|角度 %angle|时长 %duration", + "StartbitV2.setLogoServo|block": "设置乐高360°舵机ID %index 速度 %speed", "StartbitV2.startbit_runActionGroup|block":"运行动作组|编号 %index|次数 %times", "StartbitV2.startbit_stopActionGroup|block":"停止当前动作组", "StartbitV2.startbit_sendAttitude|block":"发送姿态 旋转|%pitch| 横滚|%roll",