Skip to content

Commit

Permalink
add lego 360° servo
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiwonder committed Jan 30, 2024
1 parent 330e9b4 commit 58c4e57
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions StartbitV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions _locales/zh/StartbitV2-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 58c4e57

Please sign in to comment.