-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPLEN5StackLibrary.m5b
1 lines (1 loc) · 65.5 KB
/
PLEN5StackLibrary.m5b
1
{"category":"PLEN5Stack","color":"#00a654","blocks":["__PLEN5Stack_Setup","__PLEN5Stack_Motion","__PLEN5Stack_BasicMotionMemo","__PLEN5Stack_DanceMotionMemo","__PLEN5Stack_SoccerMotionMemo","__PLEN5Stack_Servo","__PLEN5Stack_BothLED","__PLEN5Stack_RightLED","__PLEN5Stack_LeftLED","__PLEN5Stack_SetSpeed","__PLEN5Stack_GetTime","__PLEN5Stack_GetTimeMemo","__PLEN5Stack_SetupLite"],"jscode":"// Block __PLEN5Stack_Setup\nvar __PLEN5Stack_Setup_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"PLEN5Stackのセットアップ\"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_Setup'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_Setup_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_Setup'] = function(block) {\n return `\"\"\"\nPLEN5StackLibrary Ver.1.1.1\nCopyright (c) 2020, PLEN Project Company Inc.\n\"\"\"\n\n# インポート\nimport i2c_bus\nimport re\nimport math\nimport machine\nimport neopixel\nimport urequests\nimport _thread\nimport ntptime\nimport time\nimport wifiCfg\n\n# 変数の定義\nLibrary_ServoDefaultValue = [1000, 630, 300, 600, 240, 600, 1000, 720]\nLibrary_MotionNumberCache = []\nLibrary_TransitionTimeArrayCache = []\nLibrary_SearvoArrayCache = []\nLibrary_ServoBeforeValue = [0] * 8\nLibrary_i2c = i2c_bus.get(i2c_bus.M_BUS)\nLibrary_np = neopixel.NeoPixel(machine.Pin(26), 2)\n\n# グローバル変数の定義\nLibrary_ServoCurrentValue = [0] * 8\nLibrary_CurrentLEDValue = [(0, 0, 0), (0, 0, 0)]\nLibrary_MotionNumberBefore = -1\nLibrary_MotionNumberFlag = -1\nLibrary_ThreadFlag = False\nLibrary_ThreadPlayFlag = False\nLibrary_PlayFlag = False\nLibrary_ServoErrorFlag = False\nLibrary_MotionSpeed = 100\n\nfor i in range(8):\n Library_ServoCurrentValue[i] = Library_ServoDefaultValue[i]\n\n# 関数の定義\n\n\ndef Library_write8(addr, value):\n global Library_ServoErrorFlag\n try:\n cmd = bytearray(2)\n cmd[0] = addr\n cmd[1] = value\n Library_i2c.writeto(0x6A, cmd)\n except:\n Library_ServoErrorFlag = True\n\n\ndef Library_read8(ReadByteFrom, length):\n global Library_ServoErrorFlag\n try:\n _data = bytearray(2)\n _data[0] = ReadByteFrom >> 8\n _data[1] = ReadByteFrom & 0xFF\n Library_i2c.writeto(0x56, _data)\n return Library_i2c.readfrom(0x56, length)\n except:\n Library_ServoErrorFlag = True\n\n\ndef Library_servoWrite(num, degrees):\n value = math.floor(degrees * 100 * 226 / 10000) + 0x66\n Library_write8(0x08 + num * 4, value)\n if (value > 255):\n Library_write8(0x08 + num * 4 + 1, 0x01)\n else:\n Library_write8(0x08 + num * 4 + 1, 0x00)\n\n\ndef Library_setAngle(angle, Library_time):\n global Library_ServoCurrentValue\n step = [0] * 8\n Library_time /= 25\n for i in range(8):\n target = Library_ServoDefaultValue[i] - angle[i]\n if target != Library_ServoCurrentValue[i]:\n step[i] = (target - Library_ServoCurrentValue[i]) / Library_time\n for n in range(Library_time):\n BeforeTime = time.ticks_ms()\n for m in range(8):\n Library_ServoCurrentValue[m] += step[m]\n Library_servoWrite(m, Library_ServoCurrentValue[m] / 10)\n while(time.ticks_ms() - BeforeTime < 25):\n wait_ms(1)\n\n\ndef Library_GetTime(mode):\n OrganizeList = ['2000', '1', '1', 'Sat', '00', '00', '00']\n MonthList = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']\n try:\n if wifiCfg.wlan_sta.isconnected()==False:\n wifiCfg.autoConnect(lcdShow=False)\n ntp = ntptime.client(host='jp.pool.ntp.org', timezone=9)\n GetData = ntp.formatDatetime('-', ':')\n GetData = GetData.replace('-', ':')\n GetData = GetData.replace(' ', ':')\n TimeList = GetData.split(':')\n OrganizeList = [TimeList[0], MonthList[int(TimeList[1])-1], str(int(TimeList[2])),TimeList[3][0:3], TimeList[4], TimeList[5], TimeList[6]]\n except:\n None\n if mode == 0:\n return OrganizeList\n elif mode == 8:\n return ntp.getTimestamp() + 946684800 - 32400\n elif len(OrganizeList) > mode - 1:\n return OrganizeList[mode - 1]\n else:\n return \"-1\"\n\n\ndef Library_MotionStart(MotionNumber, Mode):\n # 再生モードの確認\n if Mode != 2:\n if Library_MotionNumberBefore == 70 or Library_MotionNumberBefore == 73:\n Mode = 1\n else:\n Mode = 0\n\n MotionCount = 0\n\n NeedMotionNumberList = [MotionNumber]\n if MotionNumber in [70, 71, 72, 73]:\n NeedMotionNumberList = [70, 71, 72, 73]\n\n if MotionNumber not in Library_MotionNumberCache: # キャッシュ済みか確認\n for Number in NeedMotionNumberList:\n # 歩行モーションデータの読み取り\n ReadData = Library_read8(50 + 860 * Number, 860)\n\n # モーションデータの切り出し\n MotionDataArray = str(ReadData).split('>')\n TransitionTimeArray = []\n SearvoArray = []\n\n for i in MotionDataArray:\n if re.match('^MF' + '{:02x}'.format(Number), i):\n check1 = re.match('(MF....)(....)', i)\n TransitionTimeArray.append(int(check1.group(2), 16))\n for n in range(8):\n check2 = int(i[10 + 4 * n:10 + 4 * n + 4], 16)\n if check2 >= 0x7fff:\n check2 = ~(~check2 & 0xffff)\n else:\n check2 = check2 & 0xffff\n SearvoArray.append(check2)\n # 読み込んだデータはキャッシュする\n Library_MotionNumberCache.append(Number)\n Library_TransitionTimeArrayCache.append(TransitionTimeArray)\n Library_SearvoArrayCache.append(SearvoArray)\n\n CacheNumber = Library_MotionNumberCache.index(MotionNumber)\n # キャッシュから取得する\n TransitionTimeArray = Library_TransitionTimeArrayCache[CacheNumber]\n SearvoArray = Library_SearvoArrayCache[CacheNumber]\n\n # サーボモータを動かす\n ErrorFlag = False\n LoopTimes = len(TransitionTimeArray)\n while MotionCount != LoopTimes:\n SearvoArrayCheck = []\n for i in range(8):\n count1 = 8 * MotionCount + i\n SearvoArrayCheck.append(SearvoArray[count1])\n\n MotionFlag = True\n if MotionNumber in [70, 71, 72, 73]: # 連続歩行確認\n if Mode == 1: # 中間のみ再生\n if MotionCount >= LoopTimes - 2: # 歩行最後の2モーションカット\n MotionCount += 1\n MotionFlag = False\n elif MotionCount <= 1: # 歩行最初の2モーションカット\n MotionCount += 1\n MotionFlag = False\n if Mode == 2: # 連続歩行を終了する(最後のモーションのみ再生)\n if MotionCount < LoopTimes - 2:\n MotionCount += 1\n MotionFlag = False\n else: # 歩行最後の2モーションカット\n if MotionCount >= LoopTimes - 2: # 歩行最後の2モーションカット\n MotionCount += 1\n MotionFlag = False\n\n if MotionFlag:\n if Library_ServoBeforeValue == SearvoArrayCheck: # 同じサーボ角を繰り返す場合、動作スキップする\n MotionCount += 1\n else:\n MotionCountBefore = MotionCount\n Library_setAngle(\n SearvoArrayCheck, TransitionTimeArray[MotionCount] / (Library_MotionSpeed / 100))\n MotionCount += 1\n for i in range(8):\n Library_ServoBeforeValue[i] = SearvoArrayCheck[i]\n\n\ndef Library_ContinueEnd(): # 連続歩行終了を確認\n global Library_MotionNumberBefore, Library_MotionNumberFlag, Library_ThreadFlag, Library_ThreadPlayFlag\n Library_ThreadFlag = True\n wait_ms(25)\n if Library_PlayFlag == False:\n if Library_MotionNumberBefore in [70, 71, 72, 73]:\n Library_ThreadPlayFlag = True\n Library_MotionStart(Library_MotionNumberBefore, 2)\n Library_ThreadPlayFlag = False\n Library_ThreadFlag = False\n Library_MotionNumberBefore = -1\n Library_MotionNumberFlag = -1\n\n\ndef Library_SetLED(mode, R, G, B):\n global Library_CurrentLEDValue\n if mode == 1:\n Library_CurrentLEDValue[0] = list(map(int, [G, R, B]))\n elif mode == 2:\n Library_CurrentLEDValue[1] = list(map(int, [G, R, B]))\n else:\n Library_CurrentLEDValue[0] = list(map(int, [G, R, B]))\n Library_CurrentLEDValue[1] = list(map(int, [G, R, B]))\n for x in range(2):\n for y in range(3):\n if Library_CurrentLEDValue[x][y] < 0:\n Library_CurrentLEDValue[x][y] = 0\n if Library_CurrentLEDValue[x][y] > 255:\n Library_CurrentLEDValue[x][y] = 255\n Library_np[0] = Library_CurrentLEDValue[0]\n Library_np[1] = Library_CurrentLEDValue[1]\n Library_np.write()\n\n\ndef Library_SetSpeed(speed):\n global Library_MotionSpeed\n if speed < 10:\n speed = 10\n elif speed > 250:\n speed = 250\n Library_MotionSpeed = speed\n\n\ndef Library_PlayMotion(MotionNumber):\n global Library_MotionNumberBefore, Library_MotionNumberFlag, Library_PlayFlag\n if Library_ServoErrorFlag:\n Library_ServoSetUp()\n Library_MotionNumberFlag = MotionNumber\n Check1 = 0\n Check2 = 0\n if Library_MotionNumberBefore == 70 or Library_MotionNumberBefore == 73:\n Check1 = 1\n elif Library_MotionNumberBefore == 71 or Library_MotionNumberBefore == 72:\n Check1 = 2\n if Library_MotionNumberFlag == 70 or Library_MotionNumberFlag == 73:\n Check2 = 1\n elif Library_MotionNumberFlag == 71 or Library_MotionNumberFlag == 72:\n Check2 = 2\n\n if Check1 == 0 or Check1 != Check2:\n # 連続歩行終了確認スレッドが終了するまで待つ\n while(Library_ThreadFlag):\n wait_ms(1)\n Library_PlayFlag = True\n Library_MotionStart(MotionNumber, 0)\n Library_PlayFlag = False\n Library_MotionNumberBefore = MotionNumber\n if MotionNumber in [70, 71, 72, 73]:\n # 連続歩行終了確認スレッドを実行する\n _thread.start_new_thread(Library_ContinueEnd, ())\n while(Library_ThreadFlag == False):\n wait_ms(1)\n\n\ndef Library_SetServo(ServoAngleArray, Time):\n global Library_PlayFlag\n if Library_ServoErrorFlag:\n Library_ServoSetUp()\n # 連続歩行終了確認スレッドが終了するまで待つ\n while(Library_ThreadFlag):\n wait_ms(1)\n Library_PlayFlag = True\n if Time < 25:\n Time = 25 # 25msecが限界\n Library_setAngle(ServoAngleArray, Time)\n Library_PlayFlag = False\n\n\ndef Library_ServoSetUp():\n global Library_ServoErrorFlag, Library_ServoCurrentValue\n try:\n for i in range(8):\n Library_ServoCurrentValue[i] = Library_ServoDefaultValue[i]\n Library_ServoErrorFlag = False\n Library_write8(0xFE, 0x85)\n Library_write8(0xFA, 0x00)\n Library_write8(0xFB, 0x00)\n Library_write8(0xFC, 0x66)\n Library_write8(0xFD, 0x00)\n Library_write8(0x00, 0x01)\n Library_setAngle([0] * 8, 100)\n Library_SetLED(0, 0, 50, 0)\n except:\n Library_ServoErrorFlag = True\n\n\n# 初期化\nLibrary_ServoSetUp()\n# セットアップ完了` + \"\\n\";\n};\n\n// Block __PLEN5Stack_Motion\nvar __PLEN5Stack_Motion_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1 %2\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"モーションを再生する\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"モーションを再生する\"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_Motion'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_Motion_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_Motion'] = function(block) {\n var モーションを再生する = Blockly.Python.valueToCode(block, 'モーションを再生する', Blockly.Python.ORDER_NONE);\n return `Library_PlayMotion(${モーションを再生する})` + \"\\n\";\n};\n\n// Block __PLEN5Stack_BasicMotionMemo\nvar __PLEN5Stack_BasicMotionMemo_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"《基本モーション》\"\n }\n ],\n \"message1\": \"%1\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 70 ▶ 前に進む\"\n }\n ],\n \"message2\": \"%1\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 71 ▶ 左に回る\"\n }\n ],\n \"message3\": \"%1\",\n \"args3\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 72 ▶ 右に回る\"\n }\n ],\n \"message4\": \"%1\",\n \"args4\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 73 ▶ 後ろに進む\"\n }\n ],\n \"message5\": \"%1\",\n \"args5\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 00 ▶ 左ステップ\"\n }\n ],\n \"message6\": \"%1\",\n \"args6\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 01 ▶ 前ステップ\"\n }\n ],\n \"message7\": \"%1\",\n \"args7\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 02 ▶ 右ステップ\"\n }\n ],\n \"message8\": \"%1\",\n \"args8\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 03 ▶ えっへん\"\n }\n ],\n \"message9\": \"%1\",\n \"args9\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 04 ▶ おじぎ\"\n }\n ],\n \"message10\": \"%1\",\n \"args10\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 05 ▶ こくはく\"\n }\n ],\n \"message11\": \"%1\",\n \"args11\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 06 ▶ ハグ\"\n }\n ],\n \"message12\": \"%1\",\n \"args12\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 07 ▶ はくしゅ\"\n }\n ],\n \"message13\": \"%1\",\n \"args13\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 08 ▶ ハイタッチ\"\n }\n ],\n \"message14\": \"%1\",\n \"args14\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 41 ▶ 腕をバタバタする\"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_BasicMotionMemo'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_BasicMotionMemo_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_BasicMotionMemo'] = function(block) {\n return `#メモ` + \"\\n\";\n};\n\n// Block __PLEN5Stack_DanceMotionMemo\nvar __PLEN5Stack_DanceMotionMemo_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"《ダンスモーション》\"\n }\n ],\n \"message1\": \"%1\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 30 ▶ ダンス左ステップ\"\n }\n ],\n \"message2\": \"%1\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 31 ▶ ダンス前ステップ\"\n }\n ],\n \"message3\": \"%1\",\n \"args3\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 32 ▶ ダンス右ステップ\"\n }\n ],\n \"message4\": \"%1\",\n \"args4\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 33 ▶ ダンスポーズ\"\n }\n ],\n \"message5\": \"%1\",\n \"args5\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 34 ▶ ダンスアップダウン\"\n }\n ],\n \"message6\": \"%1\",\n \"args6\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 35 ▶ ダンスくねくね\"\n }\n ],\n \"message7\": \"%1\",\n \"args7\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 36 ▶ ダンス後ろステップ\"\n }\n ],\n \"message8\": \"%1\",\n \"args8\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 37 ▶ ダンスおじぎ\"\n }\n ],\n \"message9\": \"%1\",\n \"args9\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 38 ▶ ダンスツイスト\"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_DanceMotionMemo'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_DanceMotionMemo_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_DanceMotionMemo'] = function(block) {\n return `#メモ` + \"\\n\";\n};\n\n// Block __PLEN5Stack_SoccerMotionMemo\nvar __PLEN5Stack_SoccerMotionMemo_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"《サッカーモーション》\"\n }\n ],\n \"message1\": \"%1\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 20 ▶ 左ディフェンス\"\n }\n ],\n \"message2\": \"%1\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 21 ▶ ドリブル\"\n }\n ],\n \"message3\": \"%1\",\n \"args3\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 22 ▶ 右ディフェンス\"\n }\n ],\n \"message4\": \"%1\",\n \"args4\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 23 ▶ 左キック\"\n }\n ],\n \"message5\": \"%1\",\n \"args5\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 24 ▶ ダッシュ\"\n }\n ],\n \"message6\": \"%1\",\n \"args6\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 25 ▶ 右キック\"\n }\n ],\n \"message7\": \"%1\",\n \"args7\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 26 ▶ 左パス\"\n }\n ],\n \"message8\": \"%1\",\n \"args8\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 27 ▶ パスちょうだい\"\n }\n ],\n \"message9\": \"%1\",\n \"args9\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 28 ▶ 右パス\"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_SoccerMotionMemo'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_SoccerMotionMemo_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_SoccerMotionMemo'] = function(block) {\n return `#メモ` + \"\\n\";\n};\n\n// Block __PLEN5Stack_Servo\nvar __PLEN5Stack_Servo_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"サーボモーターの角度を変更する (サーボ0~7 [deg]) [msec]\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"Angle0\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"Angle0\"\n }\n ],\n \"message2\": \"%1 %2\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \"Angle1\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"Angle1\"\n }\n ],\n \"message3\": \"%1 %2\",\n \"args3\": [\n {\n \"type\": \"field_label\",\n \"text\": \"Angle2\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"Angle2\"\n }\n ],\n \"message4\": \"%1 %2\",\n \"args4\": [\n {\n \"type\": \"field_label\",\n \"text\": \"Angle3\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"Angle3\"\n }\n ],\n \"message5\": \"%1 %2\",\n \"args5\": [\n {\n \"type\": \"field_label\",\n \"text\": \"Angle4\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"Angle4\"\n }\n ],\n \"message6\": \"%1 %2\",\n \"args6\": [\n {\n \"type\": \"field_label\",\n \"text\": \"Angle5\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"Angle5\"\n }\n ],\n \"message7\": \"%1 %2\",\n \"args7\": [\n {\n \"type\": \"field_label\",\n \"text\": \"Angle6\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"Angle6\"\n }\n ],\n \"message8\": \"%1 %2\",\n \"args8\": [\n {\n \"type\": \"field_label\",\n \"text\": \"Angle7\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"Angle7\"\n }\n ],\n \"message9\": \"%1 %2\",\n \"args9\": [\n {\n \"type\": \"field_label\",\n \"text\": \"Time\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"Time\"\n }\n ],\n \"message10\": \"%1\",\n \"args10\": [\n {\n \"type\": \"field_label\",\n \"text\": \" \"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_Servo'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_Servo_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_Servo'] = function(block) {\n var Angle0 = Blockly.Python.valueToCode(block, 'Angle0', Blockly.Python.ORDER_NONE);\nvar Angle1 = Blockly.Python.valueToCode(block, 'Angle1', Blockly.Python.ORDER_NONE);\nvar Angle2 = Blockly.Python.valueToCode(block, 'Angle2', Blockly.Python.ORDER_NONE);\nvar Angle3 = Blockly.Python.valueToCode(block, 'Angle3', Blockly.Python.ORDER_NONE);\nvar Angle4 = Blockly.Python.valueToCode(block, 'Angle4', Blockly.Python.ORDER_NONE);\nvar Angle5 = Blockly.Python.valueToCode(block, 'Angle5', Blockly.Python.ORDER_NONE);\nvar Angle6 = Blockly.Python.valueToCode(block, 'Angle6', Blockly.Python.ORDER_NONE);\nvar Angle7 = Blockly.Python.valueToCode(block, 'Angle7', Blockly.Python.ORDER_NONE);\nvar Time = Blockly.Python.valueToCode(block, 'Time', Blockly.Python.ORDER_NONE);\n return `ServoAngleArray = [(${Angle0})*10,(${Angle1})*10,(${Angle2})*-10,(${Angle3})*10,(${Angle4})*-10,(${Angle5})*-10,(${Angle6})*10,(${Angle7})*-10]\nLibrary_SetServo(ServoAngleArray,${Time})` + \"\\n\";\n};\n\n// Block __PLEN5Stack_BothLED\nvar __PLEN5Stack_BothLED_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"両目LEDの輝度を設定する (0~255)\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"R\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"R\"\n }\n ],\n \"message2\": \"%1 %2\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \"G\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"G\"\n }\n ],\n \"message3\": \"%1 %2\",\n \"args3\": [\n {\n \"type\": \"field_label\",\n \"text\": \"B\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"B\"\n }\n ],\n \"message4\": \"%1\",\n \"args4\": [\n {\n \"type\": \"field_label\",\n \"text\": \" \"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_BothLED'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_BothLED_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_BothLED'] = function(block) {\n var R = Blockly.Python.valueToCode(block, 'R', Blockly.Python.ORDER_NONE);\nvar G = Blockly.Python.valueToCode(block, 'G', Blockly.Python.ORDER_NONE);\nvar B = Blockly.Python.valueToCode(block, 'B', Blockly.Python.ORDER_NONE);\n return `Library_SetLED(0,${R},${G},${B})` + \"\\n\";\n};\n\n// Block __PLEN5Stack_RightLED\nvar __PLEN5Stack_RightLED_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"右目LEDの輝度を設定する (0~255)\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"R\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"R\"\n }\n ],\n \"message2\": \"%1 %2\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \"G\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"G\"\n }\n ],\n \"message3\": \"%1 %2\",\n \"args3\": [\n {\n \"type\": \"field_label\",\n \"text\": \"B\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"B\"\n }\n ],\n \"message4\": \"%1\",\n \"args4\": [\n {\n \"type\": \"field_label\",\n \"text\": \" \"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_RightLED'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_RightLED_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_RightLED'] = function(block) {\n var R = Blockly.Python.valueToCode(block, 'R', Blockly.Python.ORDER_NONE);\nvar G = Blockly.Python.valueToCode(block, 'G', Blockly.Python.ORDER_NONE);\nvar B = Blockly.Python.valueToCode(block, 'B', Blockly.Python.ORDER_NONE);\n return `Library_SetLED(1,${R},${G},${B})` + \"\\n\";\n};\n\n// Block __PLEN5Stack_LeftLED\nvar __PLEN5Stack_LeftLED_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"左目LEDの輝度を設定する (0~255)\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"R\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"R\"\n }\n ],\n \"message2\": \"%1 %2\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \"G\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"G\"\n }\n ],\n \"message3\": \"%1 %2\",\n \"args3\": [\n {\n \"type\": \"field_label\",\n \"text\": \"B\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"B\"\n }\n ],\n \"message4\": \"%1\",\n \"args4\": [\n {\n \"type\": \"field_label\",\n \"text\": \" \"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_LeftLED'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_LeftLED_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_LeftLED'] = function(block) {\n var R = Blockly.Python.valueToCode(block, 'R', Blockly.Python.ORDER_NONE);\nvar G = Blockly.Python.valueToCode(block, 'G', Blockly.Python.ORDER_NONE);\nvar B = Blockly.Python.valueToCode(block, 'B', Blockly.Python.ORDER_NONE);\n return `Library_SetLED(2,${R},${G},${B})` + \"\\n\";\n};\n\n// Block __PLEN5Stack_SetSpeed\nvar __PLEN5Stack_SetSpeed_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"モーション速度を変更する (%)\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"Speed\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"Speed\"\n }\n ],\n \"message2\": \"%1\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \" \"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_SetSpeed'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_SetSpeed_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_SetSpeed'] = function(block) {\n var Speed = Blockly.Python.valueToCode(block, 'Speed', Blockly.Python.ORDER_NONE);\n return `Library_SetSpeed(${Speed})` + \"\\n\";\n};\n\n// Block __PLEN5Stack_GetTime\nvar __PLEN5Stack_GetTime_json = {\n \"output\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"現在時刻を取得する\"\n }\n ],\n \"message1\": \"%1 %2\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"mode\"\n },\n {\n \"type\": \"input_value\",\n \"name\": \"mode\"\n }\n ],\n \"message2\": \"%1\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \" \"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_GetTime'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_GetTime_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_GetTime'] = function(block) {\n var mode = Blockly.Python.valueToCode(block, 'mode', Blockly.Python.ORDER_NONE);\n return [`Library_GetTime(${mode})`, Blockly.Python.ORDER_CONDITIONAL]\n};\n\n// Block __PLEN5Stack_GetTimeMemo\nvar __PLEN5Stack_GetTimeMemo_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"《現在時刻を取得する》\"\n }\n ],\n \"message1\": \"%1\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 0 ▶ 1~7をリストで取得\"\n }\n ],\n \"message2\": \"%1\",\n \"args2\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 1 ▶ 年\"\n }\n ],\n \"message3\": \"%1\",\n \"args3\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 2 ▶ 月\"\n }\n ],\n \"message4\": \"%1\",\n \"args4\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 3 ▶ 日\"\n }\n ],\n \"message5\": \"%1\",\n \"args5\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 4 ▶ 曜日\"\n }\n ],\n \"message6\": \"%1\",\n \"args6\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 5 ▶ 時\"\n }\n ],\n \"message7\": \"%1\",\n \"args7\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 6 ▶ 分\"\n }\n ],\n \"message8\": \"%1\",\n \"args8\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 7 ▶ 秒\"\n }\n ],\n \"message9\": \"%1\",\n \"args9\": [\n {\n \"type\": \"field_label\",\n \"text\": \" 8 ▶ タイムスタンプ\"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_GetTimeMemo'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_GetTimeMemo_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_GetTimeMemo'] = function(block) {\n return `#メモ` + \"\\n\";\n};\n\n// Block __PLEN5Stack_SetupLite\nvar __PLEN5Stack_SetupLite_json = {\n \"previousStatement\": null,\n \"nextStatement\": null,\n \"message0\": \"%1\",\n \"args0\": [\n {\n \"type\": \"field_label\",\n \"text\": \"PLEN5Stackのセットアップ\"\n }\n ],\n \"message1\": \"%1\",\n \"args1\": [\n {\n \"type\": \"field_label\",\n \"text\": \"※サーボ角とLED色のみ変更可能な軽量版\"\n }\n ],\n \"colour\": \"#00a654\"\n};\n\nwindow['Blockly'].Blocks['__PLEN5Stack_SetupLite'] = {\n init: function() {\n this.jsonInit(__PLEN5Stack_SetupLite_json);\n }\n};\n\nwindow['Blockly'].Python['__PLEN5Stack_SetupLite'] = function(block) {\n return `from i2c_bus import get as i2c_bus_get, M_BUS as i2c_bus_M_BUS\nfrom machine import Pin as machine_Pin\nfrom neopixel import NeoPixel as neopixel_NeoPixel\nimport math\nimport time\nLibrary_ServoDefaultValue = [1000, 630, 300, 600, 240, 600, 1000, 720]\nLibrary_ServoBeforeValue = [0] * 8\nLibrary_ServoCurrentValue = [0] * 8\nLibrary_i2c = i2c_bus_get(i2c_bus_M_BUS)\nLibrary_np = neopixel_NeoPixel(machine_Pin(26), 2)\ndef Library_write8(addr, value):\n cmd = bytearray(2)\n cmd[0] = addr\n cmd[1] = value\n Library_i2c.writeto(0x6A, cmd)\ndef Library_read8(ReadByteFrom, length):\n _data = bytearray(2)\n _data[0] = ReadByteFrom >> 8\n _data[1] = ReadByteFrom & 0xFF\n Library_i2c.writeto(0x56, _data)\n return Library_i2c.readfrom(0x56, length)\ndef Library_servoWrite(num, degrees):\n value = math.floor(degrees * 100 * 226 / 10000) + 0x66\n Library_write8(0x08 + num * 4, value)\n if (value > 255):\n Library_write8(0x08 + num * 4 + 1, 0x01)\n else:\n Library_write8(0x08 + num * 4 + 1, 0x00)\ndef Library_SetLED(mode, R, G, B):\n if mode == 0 or mode == 1:\n Library_np[0] = [G, R, B]\n if mode == 0 or mode == 2:\n Library_np[1] = [G, R, B]\n Library_np.write()\ndef Library_SetServo(angle, Library_time):\n global Library_ServoCurrentValue\n step = [0] * 8\n Library_time /= 25\n for i in range(8):\n target = Library_ServoDefaultValue[i] - angle[i]\n step[i] = (target - Library_ServoCurrentValue[i]) / Library_time\n for n in range(Library_time):\n BeforeTime = time.ticks_ms()\n for m in range(8):\n Library_ServoCurrentValue[m] += step[m]\n Library_servoWrite(m, Library_ServoCurrentValue[m] / 10)\n while(time.ticks_ms() - BeforeTime < 25):\n wait_ms(1)\nfor i in range(8):\n Library_ServoCurrentValue[i] = Library_ServoDefaultValue[i]\nLibrary_write8(0xFE, 0x85)\nLibrary_write8(0xFA, 0x00)\nLibrary_write8(0xFB, 0x00)\nLibrary_write8(0xFC, 0x66)\nLibrary_write8(0xFD, 0x00)\nLibrary_write8(0x00, 0x01)\nLibrary_SetServo([0] * 8, 100)\nLibrary_SetLED(0, 0, 50, 0)` + \"\\n\";\n};\n\n","code":{"Setup":["window['Blockly'].Python['__PLEN5Stack_Setup'] = function(block) {\n return `\"\"\"\nPLEN5StackLibrary Ver.1.1.1\nCopyright (c) 2020, PLEN Project Company Inc.\n\"\"\"\n\n# インポート\nimport i2c_bus\nimport re\nimport math\nimport machine\nimport neopixel\nimport urequests\nimport _thread\nimport ntptime\nimport time\nimport wifiCfg\n\n# 変数の定義\nLibrary_ServoDefaultValue = [1000, 630, 300, 600, 240, 600, 1000, 720]\nLibrary_MotionNumberCache = []\nLibrary_TransitionTimeArrayCache = []\nLibrary_SearvoArrayCache = []\nLibrary_ServoBeforeValue = [0] * 8\nLibrary_i2c = i2c_bus.get(i2c_bus.M_BUS)\nLibrary_np = neopixel.NeoPixel(machine.Pin(26), 2)\n\n# グローバル変数の定義\nLibrary_ServoCurrentValue = [0] * 8\nLibrary_CurrentLEDValue = [(0, 0, 0), (0, 0, 0)]\nLibrary_MotionNumberBefore = -1\nLibrary_MotionNumberFlag = -1\nLibrary_ThreadFlag = False\nLibrary_ThreadPlayFlag = False\nLibrary_PlayFlag = False\nLibrary_ServoErrorFlag = False\nLibrary_MotionSpeed = 100\n\nfor i in range(8):\n Library_ServoCurrentValue[i] = Library_ServoDefaultValue[i]\n\n# 関数の定義\n\n\ndef Library_write8(addr, value):\n global Library_ServoErrorFlag\n try:\n cmd = bytearray(2)\n cmd[0] = addr\n cmd[1] = value\n Library_i2c.writeto(0x6A, cmd)\n except:\n Library_ServoErrorFlag = True\n\n\ndef Library_read8(ReadByteFrom, length):\n global Library_ServoErrorFlag\n try:\n _data = bytearray(2)\n _data[0] = ReadByteFrom >> 8\n _data[1] = ReadByteFrom & 0xFF\n Library_i2c.writeto(0x56, _data)\n return Library_i2c.readfrom(0x56, length)\n except:\n Library_ServoErrorFlag = True\n\n\ndef Library_servoWrite(num, degrees):\n value = math.floor(degrees * 100 * 226 / 10000) + 0x66\n Library_write8(0x08 + num * 4, value)\n if (value > 255):\n Library_write8(0x08 + num * 4 + 1, 0x01)\n else:\n Library_write8(0x08 + num * 4 + 1, 0x00)\n\n\ndef Library_setAngle(angle, Library_time):\n global Library_ServoCurrentValue\n step = [0] * 8\n Library_time /= 25\n for i in range(8):\n target = Library_ServoDefaultValue[i] - angle[i]\n if target != Library_ServoCurrentValue[i]:\n step[i] = (target - Library_ServoCurrentValue[i]) / Library_time\n for n in range(Library_time):\n BeforeTime = time.ticks_ms()\n for m in range(8):\n Library_ServoCurrentValue[m] += step[m]\n Library_servoWrite(m, Library_ServoCurrentValue[m] / 10)\n while(time.ticks_ms() - BeforeTime < 25):\n wait_ms(1)\n\n\ndef Library_GetTime(mode):\n OrganizeList = ['2000', '1', '1', 'Sat', '00', '00', '00']\n MonthList = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']\n try:\n if wifiCfg.wlan_sta.isconnected()==False:\n wifiCfg.autoConnect(lcdShow=False)\n ntp = ntptime.client(host='jp.pool.ntp.org', timezone=9)\n GetData = ntp.formatDatetime('-', ':')\n GetData = GetData.replace('-', ':')\n GetData = GetData.replace(' ', ':')\n TimeList = GetData.split(':')\n OrganizeList = [TimeList[0], MonthList[int(TimeList[1])-1], str(int(TimeList[2])),TimeList[3][0:3], TimeList[4], TimeList[5], TimeList[6]]\n except:\n None\n if mode == 0:\n return OrganizeList\n elif mode == 8:\n return ntp.getTimestamp() + 946684800 - 32400\n elif len(OrganizeList) > mode - 1:\n return OrganizeList[mode - 1]\n else:\n return \"-1\"\n\n\ndef Library_MotionStart(MotionNumber, Mode):\n # 再生モードの確認\n if Mode != 2:\n if Library_MotionNumberBefore == 70 or Library_MotionNumberBefore == 73:\n Mode = 1\n else:\n Mode = 0\n\n MotionCount = 0\n\n NeedMotionNumberList = [MotionNumber]\n if MotionNumber in [70, 71, 72, 73]:\n NeedMotionNumberList = [70, 71, 72, 73]\n\n if MotionNumber not in Library_MotionNumberCache: # キャッシュ済みか確認\n for Number in NeedMotionNumberList:\n # 歩行モーションデータの読み取り\n ReadData = Library_read8(50 + 860 * Number, 860)\n\n # モーションデータの切り出し\n MotionDataArray = str(ReadData).split('>')\n TransitionTimeArray = []\n SearvoArray = []\n\n for i in MotionDataArray:\n if re.match('^MF' + '{:02x}'.format(Number), i):\n check1 = re.match('(MF....)(....)', i)\n TransitionTimeArray.append(int(check1.group(2), 16))\n for n in range(8):\n check2 = int(i[10 + 4 * n:10 + 4 * n + 4], 16)\n if check2 >= 0x7fff:\n check2 = ~(~check2 & 0xffff)\n else:\n check2 = check2 & 0xffff\n SearvoArray.append(check2)\n # 読み込んだデータはキャッシュする\n Library_MotionNumberCache.append(Number)\n Library_TransitionTimeArrayCache.append(TransitionTimeArray)\n Library_SearvoArrayCache.append(SearvoArray)\n\n CacheNumber = Library_MotionNumberCache.index(MotionNumber)\n # キャッシュから取得する\n TransitionTimeArray = Library_TransitionTimeArrayCache[CacheNumber]\n SearvoArray = Library_SearvoArrayCache[CacheNumber]\n\n # サーボモータを動かす\n ErrorFlag = False\n LoopTimes = len(TransitionTimeArray)\n while MotionCount != LoopTimes:\n SearvoArrayCheck = []\n for i in range(8):\n count1 = 8 * MotionCount + i\n SearvoArrayCheck.append(SearvoArray[count1])\n\n MotionFlag = True\n if MotionNumber in [70, 71, 72, 73]: # 連続歩行確認\n if Mode == 1: # 中間のみ再生\n if MotionCount >= LoopTimes - 2: # 歩行最後の2モーションカット\n MotionCount += 1\n MotionFlag = False\n elif MotionCount <= 1: # 歩行最初の2モーションカット\n MotionCount += 1\n MotionFlag = False\n if Mode == 2: # 連続歩行を終了する(最後のモーションのみ再生)\n if MotionCount < LoopTimes - 2:\n MotionCount += 1\n MotionFlag = False\n else: # 歩行最後の2モーションカット\n if MotionCount >= LoopTimes - 2: # 歩行最後の2モーションカット\n MotionCount += 1\n MotionFlag = False\n\n if MotionFlag:\n if Library_ServoBeforeValue == SearvoArrayCheck: # 同じサーボ角を繰り返す場合、動作スキップする\n MotionCount += 1\n else:\n MotionCountBefore = MotionCount\n Library_setAngle(\n SearvoArrayCheck, TransitionTimeArray[MotionCount] / (Library_MotionSpeed / 100))\n MotionCount += 1\n for i in range(8):\n Library_ServoBeforeValue[i] = SearvoArrayCheck[i]\n\n\ndef Library_ContinueEnd(): # 連続歩行終了を確認\n global Library_MotionNumberBefore, Library_MotionNumberFlag, Library_ThreadFlag, Library_ThreadPlayFlag\n Library_ThreadFlag = True\n wait_ms(25)\n if Library_PlayFlag == False:\n if Library_MotionNumberBefore in [70, 71, 72, 73]:\n Library_ThreadPlayFlag = True\n Library_MotionStart(Library_MotionNumberBefore, 2)\n Library_ThreadPlayFlag = False\n Library_ThreadFlag = False\n Library_MotionNumberBefore = -1\n Library_MotionNumberFlag = -1\n\n\ndef Library_SetLED(mode, R, G, B):\n global Library_CurrentLEDValue\n if mode == 1:\n Library_CurrentLEDValue[0] = list(map(int, [G, R, B]))\n elif mode == 2:\n Library_CurrentLEDValue[1] = list(map(int, [G, R, B]))\n else:\n Library_CurrentLEDValue[0] = list(map(int, [G, R, B]))\n Library_CurrentLEDValue[1] = list(map(int, [G, R, B]))\n for x in range(2):\n for y in range(3):\n if Library_CurrentLEDValue[x][y] < 0:\n Library_CurrentLEDValue[x][y] = 0\n if Library_CurrentLEDValue[x][y] > 255:\n Library_CurrentLEDValue[x][y] = 255\n Library_np[0] = Library_CurrentLEDValue[0]\n Library_np[1] = Library_CurrentLEDValue[1]\n Library_np.write()\n\n\ndef Library_SetSpeed(speed):\n global Library_MotionSpeed\n if speed < 10:\n speed = 10\n elif speed > 250:\n speed = 250\n Library_MotionSpeed = speed\n\n\ndef Library_PlayMotion(MotionNumber):\n global Library_MotionNumberBefore, Library_MotionNumberFlag, Library_PlayFlag\n if Library_ServoErrorFlag:\n Library_ServoSetUp()\n Library_MotionNumberFlag = MotionNumber\n Check1 = 0\n Check2 = 0\n if Library_MotionNumberBefore == 70 or Library_MotionNumberBefore == 73:\n Check1 = 1\n elif Library_MotionNumberBefore == 71 or Library_MotionNumberBefore == 72:\n Check1 = 2\n if Library_MotionNumberFlag == 70 or Library_MotionNumberFlag == 73:\n Check2 = 1\n elif Library_MotionNumberFlag == 71 or Library_MotionNumberFlag == 72:\n Check2 = 2\n\n if Check1 == 0 or Check1 != Check2:\n # 連続歩行終了確認スレッドが終了するまで待つ\n while(Library_ThreadFlag):\n wait_ms(1)\n Library_PlayFlag = True\n Library_MotionStart(MotionNumber, 0)\n Library_PlayFlag = False\n Library_MotionNumberBefore = MotionNumber\n if MotionNumber in [70, 71, 72, 73]:\n # 連続歩行終了確認スレッドを実行する\n _thread.start_new_thread(Library_ContinueEnd, ())\n while(Library_ThreadFlag == False):\n wait_ms(1)\n\n\ndef Library_SetServo(ServoAngleArray, Time):\n global Library_PlayFlag\n if Library_ServoErrorFlag:\n Library_ServoSetUp()\n # 連続歩行終了確認スレッドが終了するまで待つ\n while(Library_ThreadFlag):\n wait_ms(1)\n Library_PlayFlag = True\n if Time < 25:\n Time = 25 # 25msecが限界\n Library_setAngle(ServoAngleArray, Time)\n Library_PlayFlag = False\n\n\ndef Library_ServoSetUp():\n global Library_ServoErrorFlag, Library_ServoCurrentValue\n try:\n for i in range(8):\n Library_ServoCurrentValue[i] = Library_ServoDefaultValue[i]\n Library_ServoErrorFlag = False\n Library_write8(0xFE, 0x85)\n Library_write8(0xFA, 0x00)\n Library_write8(0xFB, 0x00)\n Library_write8(0xFC, 0x66)\n Library_write8(0xFD, 0x00)\n Library_write8(0x00, 0x01)\n Library_setAngle([0] * 8, 100)\n Library_SetLED(0, 0, 50, 0)\n except:\n Library_ServoErrorFlag = True\n\n\n# 初期化\nLibrary_ServoSetUp()\n# セットアップ完了` + \"\\n\";\n};\n\n","\"\"\"\nPLEN5StackLibrary Ver.1.1.1\nCopyright (c) 2020, PLEN Project Company Inc.\n\"\"\"\n\n# インポート\nimport i2c_bus\nimport re\nimport math\nimport machine\nimport neopixel\nimport urequests\nimport _thread\nimport ntptime\nimport time\nimport wifiCfg\n\n# 変数の定義\nLibrary_ServoDefaultValue = [1000, 630, 300, 600, 240, 600, 1000, 720]\nLibrary_MotionNumberCache = []\nLibrary_TransitionTimeArrayCache = []\nLibrary_SearvoArrayCache = []\nLibrary_ServoBeforeValue = [0] * 8\nLibrary_i2c = i2c_bus.get(i2c_bus.M_BUS)\nLibrary_np = neopixel.NeoPixel(machine.Pin(26), 2)\n\n# グローバル変数の定義\nLibrary_ServoCurrentValue = [0] * 8\nLibrary_CurrentLEDValue = [(0, 0, 0), (0, 0, 0)]\nLibrary_MotionNumberBefore = -1\nLibrary_MotionNumberFlag = -1\nLibrary_ThreadFlag = False\nLibrary_ThreadPlayFlag = False\nLibrary_PlayFlag = False\nLibrary_ServoErrorFlag = False\nLibrary_MotionSpeed = 100\n\nfor i in range(8):\n Library_ServoCurrentValue[i] = Library_ServoDefaultValue[i]\n\n# 関数の定義\n\n\ndef Library_write8(addr, value):\n global Library_ServoErrorFlag\n try:\n cmd = bytearray(2)\n cmd[0] = addr\n cmd[1] = value\n Library_i2c.writeto(0x6A, cmd)\n except:\n Library_ServoErrorFlag = True\n\n\ndef Library_read8(ReadByteFrom, length):\n global Library_ServoErrorFlag\n try:\n _data = bytearray(2)\n _data[0] = ReadByteFrom >> 8\n _data[1] = ReadByteFrom & 0xFF\n Library_i2c.writeto(0x56, _data)\n return Library_i2c.readfrom(0x56, length)\n except:\n Library_ServoErrorFlag = True\n\n\ndef Library_servoWrite(num, degrees):\n value = math.floor(degrees * 100 * 226 / 10000) + 0x66\n Library_write8(0x08 + num * 4, value)\n if (value > 255):\n Library_write8(0x08 + num * 4 + 1, 0x01)\n else:\n Library_write8(0x08 + num * 4 + 1, 0x00)\n\n\ndef Library_setAngle(angle, Library_time):\n global Library_ServoCurrentValue\n step = [0] * 8\n Library_time /= 25\n for i in range(8):\n target = Library_ServoDefaultValue[i] - angle[i]\n if target != Library_ServoCurrentValue[i]:\n step[i] = (target - Library_ServoCurrentValue[i]) / Library_time\n for n in range(Library_time):\n BeforeTime = time.ticks_ms()\n for m in range(8):\n Library_ServoCurrentValue[m] += step[m]\n Library_servoWrite(m, Library_ServoCurrentValue[m] / 10)\n while(time.ticks_ms() - BeforeTime < 25):\n wait_ms(1)\n\n\ndef Library_GetTime(mode):\n OrganizeList = ['2000', '1', '1', 'Sat', '00', '00', '00']\n MonthList = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']\n try:\n if wifiCfg.wlan_sta.isconnected()==False:\n wifiCfg.autoConnect(lcdShow=False)\n ntp = ntptime.client(host='jp.pool.ntp.org', timezone=9)\n GetData = ntp.formatDatetime('-', ':')\n GetData = GetData.replace('-', ':')\n GetData = GetData.replace(' ', ':')\n TimeList = GetData.split(':')\n OrganizeList = [TimeList[0], MonthList[int(TimeList[1])-1], str(int(TimeList[2])),TimeList[3][0:3], TimeList[4], TimeList[5], TimeList[6]]\n except:\n None\n if mode == 0:\n return OrganizeList\n elif mode == 8:\n return ntp.getTimestamp() + 946684800 - 32400\n elif len(OrganizeList) > mode - 1:\n return OrganizeList[mode - 1]\n else:\n return \"-1\"\n\n\ndef Library_MotionStart(MotionNumber, Mode):\n # 再生モードの確認\n if Mode != 2:\n if Library_MotionNumberBefore == 70 or Library_MotionNumberBefore == 73:\n Mode = 1\n else:\n Mode = 0\n\n MotionCount = 0\n\n NeedMotionNumberList = [MotionNumber]\n if MotionNumber in [70, 71, 72, 73]:\n NeedMotionNumberList = [70, 71, 72, 73]\n\n if MotionNumber not in Library_MotionNumberCache: # キャッシュ済みか確認\n for Number in NeedMotionNumberList:\n # 歩行モーションデータの読み取り\n ReadData = Library_read8(50 + 860 * Number, 860)\n\n # モーションデータの切り出し\n MotionDataArray = str(ReadData).split('>')\n TransitionTimeArray = []\n SearvoArray = []\n\n for i in MotionDataArray:\n if re.match('^MF' + '{:02x}'.format(Number), i):\n check1 = re.match('(MF....)(....)', i)\n TransitionTimeArray.append(int(check1.group(2), 16))\n for n in range(8):\n check2 = int(i[10 + 4 * n:10 + 4 * n + 4], 16)\n if check2 >= 0x7fff:\n check2 = ~(~check2 & 0xffff)\n else:\n check2 = check2 & 0xffff\n SearvoArray.append(check2)\n # 読み込んだデータはキャッシュする\n Library_MotionNumberCache.append(Number)\n Library_TransitionTimeArrayCache.append(TransitionTimeArray)\n Library_SearvoArrayCache.append(SearvoArray)\n\n CacheNumber = Library_MotionNumberCache.index(MotionNumber)\n # キャッシュから取得する\n TransitionTimeArray = Library_TransitionTimeArrayCache[CacheNumber]\n SearvoArray = Library_SearvoArrayCache[CacheNumber]\n\n # サーボモータを動かす\n ErrorFlag = False\n LoopTimes = len(TransitionTimeArray)\n while MotionCount != LoopTimes:\n SearvoArrayCheck = []\n for i in range(8):\n count1 = 8 * MotionCount + i\n SearvoArrayCheck.append(SearvoArray[count1])\n\n MotionFlag = True\n if MotionNumber in [70, 71, 72, 73]: # 連続歩行確認\n if Mode == 1: # 中間のみ再生\n if MotionCount >= LoopTimes - 2: # 歩行最後の2モーションカット\n MotionCount += 1\n MotionFlag = False\n elif MotionCount <= 1: # 歩行最初の2モーションカット\n MotionCount += 1\n MotionFlag = False\n if Mode == 2: # 連続歩行を終了する(最後のモーションのみ再生)\n if MotionCount < LoopTimes - 2:\n MotionCount += 1\n MotionFlag = False\n else: # 歩行最後の2モーションカット\n if MotionCount >= LoopTimes - 2: # 歩行最後の2モーションカット\n MotionCount += 1\n MotionFlag = False\n\n if MotionFlag:\n if Library_ServoBeforeValue == SearvoArrayCheck: # 同じサーボ角を繰り返す場合、動作スキップする\n MotionCount += 1\n else:\n MotionCountBefore = MotionCount\n Library_setAngle(\n SearvoArrayCheck, TransitionTimeArray[MotionCount] / (Library_MotionSpeed / 100))\n MotionCount += 1\n for i in range(8):\n Library_ServoBeforeValue[i] = SearvoArrayCheck[i]\n\n\ndef Library_ContinueEnd(): # 連続歩行終了を確認\n global Library_MotionNumberBefore, Library_MotionNumberFlag, Library_ThreadFlag, Library_ThreadPlayFlag\n Library_ThreadFlag = True\n wait_ms(25)\n if Library_PlayFlag == False:\n if Library_MotionNumberBefore in [70, 71, 72, 73]:\n Library_ThreadPlayFlag = True\n Library_MotionStart(Library_MotionNumberBefore, 2)\n Library_ThreadPlayFlag = False\n Library_ThreadFlag = False\n Library_MotionNumberBefore = -1\n Library_MotionNumberFlag = -1\n\n\ndef Library_SetLED(mode, R, G, B):\n global Library_CurrentLEDValue\n if mode == 1:\n Library_CurrentLEDValue[0] = list(map(int, [G, R, B]))\n elif mode == 2:\n Library_CurrentLEDValue[1] = list(map(int, [G, R, B]))\n else:\n Library_CurrentLEDValue[0] = list(map(int, [G, R, B]))\n Library_CurrentLEDValue[1] = list(map(int, [G, R, B]))\n for x in range(2):\n for y in range(3):\n if Library_CurrentLEDValue[x][y] < 0:\n Library_CurrentLEDValue[x][y] = 0\n if Library_CurrentLEDValue[x][y] > 255:\n Library_CurrentLEDValue[x][y] = 255\n Library_np[0] = Library_CurrentLEDValue[0]\n Library_np[1] = Library_CurrentLEDValue[1]\n Library_np.write()\n\n\ndef Library_SetSpeed(speed):\n global Library_MotionSpeed\n if speed < 10:\n speed = 10\n elif speed > 250:\n speed = 250\n Library_MotionSpeed = speed\n\n\ndef Library_PlayMotion(MotionNumber):\n global Library_MotionNumberBefore, Library_MotionNumberFlag, Library_PlayFlag\n if Library_ServoErrorFlag:\n Library_ServoSetUp()\n Library_MotionNumberFlag = MotionNumber\n Check1 = 0\n Check2 = 0\n if Library_MotionNumberBefore == 70 or Library_MotionNumberBefore == 73:\n Check1 = 1\n elif Library_MotionNumberBefore == 71 or Library_MotionNumberBefore == 72:\n Check1 = 2\n if Library_MotionNumberFlag == 70 or Library_MotionNumberFlag == 73:\n Check2 = 1\n elif Library_MotionNumberFlag == 71 or Library_MotionNumberFlag == 72:\n Check2 = 2\n\n if Check1 == 0 or Check1 != Check2:\n # 連続歩行終了確認スレッドが終了するまで待つ\n while(Library_ThreadFlag):\n wait_ms(1)\n Library_PlayFlag = True\n Library_MotionStart(MotionNumber, 0)\n Library_PlayFlag = False\n Library_MotionNumberBefore = MotionNumber\n if MotionNumber in [70, 71, 72, 73]:\n # 連続歩行終了確認スレッドを実行する\n _thread.start_new_thread(Library_ContinueEnd, ())\n while(Library_ThreadFlag == False):\n wait_ms(1)\n\n\ndef Library_SetServo(ServoAngleArray, Time):\n global Library_PlayFlag\n if Library_ServoErrorFlag:\n Library_ServoSetUp()\n # 連続歩行終了確認スレッドが終了するまで待つ\n while(Library_ThreadFlag):\n wait_ms(1)\n Library_PlayFlag = True\n if Time < 25:\n Time = 25 # 25msecが限界\n Library_setAngle(ServoAngleArray, Time)\n Library_PlayFlag = False\n\n\ndef Library_ServoSetUp():\n global Library_ServoErrorFlag, Library_ServoCurrentValue\n try:\n for i in range(8):\n Library_ServoCurrentValue[i] = Library_ServoDefaultValue[i]\n Library_ServoErrorFlag = False\n Library_write8(0xFE, 0x85)\n Library_write8(0xFA, 0x00)\n Library_write8(0xFB, 0x00)\n Library_write8(0xFC, 0x66)\n Library_write8(0xFD, 0x00)\n Library_write8(0x00, 0x01)\n Library_setAngle([0] * 8, 100)\n Library_SetLED(0, 0, 50, 0)\n except:\n Library_ServoErrorFlag = True\n\n\n# 初期化\nLibrary_ServoSetUp()\n# セットアップ完了"],"Motion":["window['Blockly'].Python['__PLEN5Stack_Motion'] = function(block) {\n var モーションを再生する = Blockly.Python.valueToCode(block, 'モーションを再生する', Blockly.Python.ORDER_NONE);\n return `Library_PlayMotion(${モーションを再生する})` + \"\\n\";\n};\n\n","Library_PlayMotion(${モーションを再生する})"],"BasicMotionMemo":["window['Blockly'].Python['__PLEN5Stack_BasicMotionMemo'] = function(block) {\n return `#メモ` + \"\\n\";\n};\n\n","#メモ"],"DanceMotionMemo":["window['Blockly'].Python['__PLEN5Stack_DanceMotionMemo'] = function(block) {\n return `#メモ` + \"\\n\";\n};\n\n","#メモ"],"SoccerMotionMemo":["window['Blockly'].Python['__PLEN5Stack_SoccerMotionMemo'] = function(block) {\n return `#メモ` + \"\\n\";\n};\n\n","#メモ"],"Servo":["window['Blockly'].Python['__PLEN5Stack_Servo'] = function(block) {\n var Angle0 = Blockly.Python.valueToCode(block, 'Angle0', Blockly.Python.ORDER_NONE);\nvar Angle1 = Blockly.Python.valueToCode(block, 'Angle1', Blockly.Python.ORDER_NONE);\nvar Angle2 = Blockly.Python.valueToCode(block, 'Angle2', Blockly.Python.ORDER_NONE);\nvar Angle3 = Blockly.Python.valueToCode(block, 'Angle3', Blockly.Python.ORDER_NONE);\nvar Angle4 = Blockly.Python.valueToCode(block, 'Angle4', Blockly.Python.ORDER_NONE);\nvar Angle5 = Blockly.Python.valueToCode(block, 'Angle5', Blockly.Python.ORDER_NONE);\nvar Angle6 = Blockly.Python.valueToCode(block, 'Angle6', Blockly.Python.ORDER_NONE);\nvar Angle7 = Blockly.Python.valueToCode(block, 'Angle7', Blockly.Python.ORDER_NONE);\nvar Time = Blockly.Python.valueToCode(block, 'Time', Blockly.Python.ORDER_NONE);\n return `ServoAngleArray = [(${Angle0})*10,(${Angle1})*10,(${Angle2})*-10,(${Angle3})*10,(${Angle4})*-10,(${Angle5})*-10,(${Angle6})*10,(${Angle7})*-10]\nLibrary_SetServo(ServoAngleArray,${Time})` + \"\\n\";\n};\n\n","ServoAngleArray = [(${Angle0})*10,(${Angle1})*10,(${Angle2})*-10,(${Angle3})*10,(${Angle4})*-10,(${Angle5})*-10,(${Angle6})*10,(${Angle7})*-10]\nLibrary_SetServo(ServoAngleArray,${Time})"],"BothLED":["window['Blockly'].Python['__PLEN5Stack_BothLED'] = function(block) {\n var R = Blockly.Python.valueToCode(block, 'R', Blockly.Python.ORDER_NONE);\nvar G = Blockly.Python.valueToCode(block, 'G', Blockly.Python.ORDER_NONE);\nvar B = Blockly.Python.valueToCode(block, 'B', Blockly.Python.ORDER_NONE);\n return `Library_SetLED(0,${R},${G},${B})` + \"\\n\";\n};\n\n","Library_SetLED(0,${R},${G},${B})"],"RightLED":["window['Blockly'].Python['__PLEN5Stack_RightLED'] = function(block) {\n var R = Blockly.Python.valueToCode(block, 'R', Blockly.Python.ORDER_NONE);\nvar G = Blockly.Python.valueToCode(block, 'G', Blockly.Python.ORDER_NONE);\nvar B = Blockly.Python.valueToCode(block, 'B', Blockly.Python.ORDER_NONE);\n return `Library_SetLED(1,${R},${G},${B})` + \"\\n\";\n};\n\n","Library_SetLED(1,${R},${G},${B})"],"LeftLED":["window['Blockly'].Python['__PLEN5Stack_LeftLED'] = function(block) {\n var R = Blockly.Python.valueToCode(block, 'R', Blockly.Python.ORDER_NONE);\nvar G = Blockly.Python.valueToCode(block, 'G', Blockly.Python.ORDER_NONE);\nvar B = Blockly.Python.valueToCode(block, 'B', Blockly.Python.ORDER_NONE);\n return `Library_SetLED(2,${R},${G},${B})` + \"\\n\";\n};\n\n","Library_SetLED(2,${R},${G},${B})"],"SetSpeed":["window['Blockly'].Python['__PLEN5Stack_SetSpeed'] = function(block) {\n var Speed = Blockly.Python.valueToCode(block, 'Speed', Blockly.Python.ORDER_NONE);\n return `Library_SetSpeed(${Speed})` + \"\\n\";\n};\n\n","Library_SetSpeed(${Speed})"],"GetTime":["window['Blockly'].Python['__PLEN5Stack_GetTime'] = function(block) {\n var mode = Blockly.Python.valueToCode(block, 'mode', Blockly.Python.ORDER_NONE);\n return [`Library_GetTime(${mode})`, Blockly.Python.ORDER_CONDITIONAL]\n};\n\n","Library_GetTime(${mode})"],"GetTimeMemo":["window['Blockly'].Python['__PLEN5Stack_GetTimeMemo'] = function(block) {\n return `#メモ` + \"\\n\";\n};\n\n","#メモ"],"SetupLite":["window['Blockly'].Python['__PLEN5Stack_SetupLite'] = function(block) {\n return `from i2c_bus import get as i2c_bus_get, M_BUS as i2c_bus_M_BUS\nfrom machine import Pin as machine_Pin\nfrom neopixel import NeoPixel as neopixel_NeoPixel\nimport math\nimport time\nLibrary_ServoDefaultValue = [1000, 630, 300, 600, 240, 600, 1000, 720]\nLibrary_ServoBeforeValue = [0] * 8\nLibrary_ServoCurrentValue = [0] * 8\nLibrary_i2c = i2c_bus_get(i2c_bus_M_BUS)\nLibrary_np = neopixel_NeoPixel(machine_Pin(26), 2)\ndef Library_write8(addr, value):\n cmd = bytearray(2)\n cmd[0] = addr\n cmd[1] = value\n Library_i2c.writeto(0x6A, cmd)\ndef Library_read8(ReadByteFrom, length):\n _data = bytearray(2)\n _data[0] = ReadByteFrom >> 8\n _data[1] = ReadByteFrom & 0xFF\n Library_i2c.writeto(0x56, _data)\n return Library_i2c.readfrom(0x56, length)\ndef Library_servoWrite(num, degrees):\n value = math.floor(degrees * 100 * 226 / 10000) + 0x66\n Library_write8(0x08 + num * 4, value)\n if (value > 255):\n Library_write8(0x08 + num * 4 + 1, 0x01)\n else:\n Library_write8(0x08 + num * 4 + 1, 0x00)\ndef Library_SetLED(mode, R, G, B):\n if mode == 0 or mode == 1:\n Library_np[0] = [G, R, B]\n if mode == 0 or mode == 2:\n Library_np[1] = [G, R, B]\n Library_np.write()\ndef Library_SetServo(angle, Library_time):\n global Library_ServoCurrentValue\n step = [0] * 8\n Library_time /= 25\n for i in range(8):\n target = Library_ServoDefaultValue[i] - angle[i]\n step[i] = (target - Library_ServoCurrentValue[i]) / Library_time\n for n in range(Library_time):\n BeforeTime = time.ticks_ms()\n for m in range(8):\n Library_ServoCurrentValue[m] += step[m]\n Library_servoWrite(m, Library_ServoCurrentValue[m] / 10)\n while(time.ticks_ms() - BeforeTime < 25):\n wait_ms(1)\nfor i in range(8):\n Library_ServoCurrentValue[i] = Library_ServoDefaultValue[i]\nLibrary_write8(0xFE, 0x85)\nLibrary_write8(0xFA, 0x00)\nLibrary_write8(0xFB, 0x00)\nLibrary_write8(0xFC, 0x66)\nLibrary_write8(0xFD, 0x00)\nLibrary_write8(0x00, 0x01)\nLibrary_SetServo([0] * 8, 100)\nLibrary_SetLED(0, 0, 50, 0)` + \"\\n\";\n};\n\n","from i2c_bus import get as i2c_bus_get, M_BUS as i2c_bus_M_BUS\nfrom machine import Pin as machine_Pin\nfrom neopixel import NeoPixel as neopixel_NeoPixel\nimport math\nimport time\nLibrary_ServoDefaultValue = [1000, 630, 300, 600, 240, 600, 1000, 720]\nLibrary_ServoBeforeValue = [0] * 8\nLibrary_ServoCurrentValue = [0] * 8\nLibrary_i2c = i2c_bus_get(i2c_bus_M_BUS)\nLibrary_np = neopixel_NeoPixel(machine_Pin(26), 2)\ndef Library_write8(addr, value):\n cmd = bytearray(2)\n cmd[0] = addr\n cmd[1] = value\n Library_i2c.writeto(0x6A, cmd)\ndef Library_read8(ReadByteFrom, length):\n _data = bytearray(2)\n _data[0] = ReadByteFrom >> 8\n _data[1] = ReadByteFrom & 0xFF\n Library_i2c.writeto(0x56, _data)\n return Library_i2c.readfrom(0x56, length)\ndef Library_servoWrite(num, degrees):\n value = math.floor(degrees * 100 * 226 / 10000) + 0x66\n Library_write8(0x08 + num * 4, value)\n if (value > 255):\n Library_write8(0x08 + num * 4 + 1, 0x01)\n else:\n Library_write8(0x08 + num * 4 + 1, 0x00)\ndef Library_SetLED(mode, R, G, B):\n if mode == 0 or mode == 1:\n Library_np[0] = [G, R, B]\n if mode == 0 or mode == 2:\n Library_np[1] = [G, R, B]\n Library_np.write()\ndef Library_SetServo(angle, Library_time):\n global Library_ServoCurrentValue\n step = [0] * 8\n Library_time /= 25\n for i in range(8):\n target = Library_ServoDefaultValue[i] - angle[i]\n step[i] = (target - Library_ServoCurrentValue[i]) / Library_time\n for n in range(Library_time):\n BeforeTime = time.ticks_ms()\n for m in range(8):\n Library_ServoCurrentValue[m] += step[m]\n Library_servoWrite(m, Library_ServoCurrentValue[m] / 10)\n while(time.ticks_ms() - BeforeTime < 25):\n wait_ms(1)\nfor i in range(8):\n Library_ServoCurrentValue[i] = Library_ServoDefaultValue[i]\nLibrary_write8(0xFE, 0x85)\nLibrary_write8(0xFA, 0x00)\nLibrary_write8(0xFB, 0x00)\nLibrary_write8(0xFC, 0x66)\nLibrary_write8(0xFD, 0x00)\nLibrary_write8(0x00, 0x01)\nLibrary_SetServo([0] * 8, 100)\nLibrary_SetLED(0, 0, 50, 0)"]}}