From 4dc3af0b18100b821dab87509ae91abad3b31a30 Mon Sep 17 00:00:00 2001 From: tiandiyishaou Date: Mon, 11 Mar 2024 17:59:51 +0800 Subject: [PATCH] add sound level --- StartbitV2.ts | 57 ++++++----------------------- _locales/zh/StartbitV2-strings.json | 3 +- 2 files changed, 14 insertions(+), 46 deletions(-) diff --git a/StartbitV2.ts b/StartbitV2.ts index 8ea77ae..29768e4 100644 --- a/StartbitV2.ts +++ b/StartbitV2.ts @@ -330,7 +330,7 @@ namespace StartbitV2 { let lhRGBLightBelt: StartbitRGBLight.LHstartbitRGBLight; let P14_ad = 0; - + let soundLevel = 0; let MESSAGE_MAC = 0xff; let MESSAGE_ANGLE = 0x100; @@ -369,6 +369,7 @@ namespace StartbitV2 { let arg3Int: number = strToNumber(cmd.substr(5, 2)); P14_ad = arg1Int; + soundLevel = arg2Int; if (arg3Int != -1) { currentVoltage = arg3Int * 78.63; @@ -381,49 +382,6 @@ namespace StartbitV2 { } } - if (cmd.charAt(0).compare("C") == 0 && cmd.length == 11) { - if (lhRGBLightBelt != null) { - for (let i = 0; i < 10; i++) { - let color = converOneChar(cmd.charAt(i + 1)); - if (color != -1) - lhRGBLightBelt.setPixelColor(i, color); - } - lhRGBLightBelt.show(); - } - } - if (cmd.charAt(0).compare("M") == 0 && cmd.length == 18) { - macStr = cmd.substr(1, 17); - control.raiseEvent(MESSAGE_MAC, 1); - } - if (cmd.compare("WIFI_S_CONNECT") == 0) { - connectStatus = true; - } - if (cmd.compare("WIFI_S_DISCONNECT") == 0) { - connectStatus = false; - } - if (cmd.charAt(0).compare("S") == 0 && cmd.length == 5) { - let arg1Int: number = strToNumber(cmd.substr(1, 1)); - let arg2Str = cmd.substr(2, 3); - if (arg2Str.compare("XXX") == 0) { - return; - } - let arg2Int: number = 0; - if (arg2Str.charAt(0).compare("F") != 0) { - arg2Int = strToNumber(arg2Str); - } - if (arg2Int > 1000) - arg2Int = 1000; - if (arg1Int == 1) { - servo1Angle = mapRGB(arg2Int, 0, 1000, 0, 240); - servo1Angle -= 120; - control.raiseEvent(MESSAGE_ANGLE, 1); - } - else if (arg1Int == 2) { - servo2Angle = mapRGB(arg2Int, 0, 1000, 0, 240); - servo2Angle -= 120; - control.raiseEvent(MESSAGE_ANGLE, 2); - } - } } handleCmd = ""; } @@ -768,11 +726,20 @@ namespace StartbitV2 { /** * Get startbit current voltage,the unit is mV */ - //% weight=93 blockGap=50 blockId=startbit_getBatVoltage block="Get startbit current voltage (mV)" + //% weight=93 blockId=startbit_getBatVoltage block="Get startbit current voltage (mV)" //% subcategory=Sensor export function startbit_getBatVoltage(): number { return currentVoltage; } + + /** + * Get startbit sound level + */ + //% weight=92 blockGap=50 blockId=startbit_getSoundLevel block="Get startbit sound level (0~255)" + //% subcategory=Sensor + export function startbit_getSoundLevel(): number { + return soundLevel; + } /** * TM1640 LED display diff --git a/_locales/zh/StartbitV2-strings.json b/_locales/zh/StartbitV2-strings.json index 8ce47de..daccd08 100644 --- a/_locales/zh/StartbitV2-strings.json +++ b/_locales/zh/StartbitV2-strings.json @@ -193,5 +193,6 @@ "StartbitV2.startbit_MP3_BUTTON|block":"MP3模块 |%button 歌曲", "StartbitV2.startbit_MP3_VOL|block":"MP3模块音量 |%value", "StartbitV2.startbit_MP3_SINGLE_LOOP|block":"MP3模块单曲循环 |%state", - "StartbitV2.startbit_MP3_PLAY_NUM|block":"MP3模块播放序号|%num 歌曲" + "StartbitV2.startbit_MP3_PLAY_NUM|block":"MP3模块播放序号|%num 歌曲", + "StartbitV2.startbit_getSoundLevel|block":"获取音量等级(0~255)" }