8. Ring:bit六合一搭建套件案例06:投石机#

8.1. 目的#


  • 使用Ring:bit六合一搭建套件制作投石机

../../_images/Ringbit_Bricks_Pack_case_06_01.png

8.2. 使用材料#


六合一积木搭建套件(淘宝购买链接)

../../_images/Ringbit_Bricks_Pack_case_06_02.png

8.3. 背景知识#


8.4. 积木搭建#


../../_images/Ringbit_Bricks_Pack_step_06_00.png

../../_images/Ringbit_Bricks_Pack_step_06_01.png

../../_images/Ringbit_Bricks_Pack_step_06_02.png

../../_images/Ringbit_Bricks_Pack_step_06_03.png

../../_images/Ringbit_Bricks_Pack_step_06_04.png

../../_images/Ringbit_Bricks_Pack_step_06_05.png

../../_images/Ringbit_Bricks_Pack_step_06_06.png

../../_images/Ringbit_Bricks_Pack_step_06_07.png

../../_images/Ringbit_Bricks_Pack_step_06_08.png

../../_images/Ringbit_Bricks_Pack_step_06_09.png

../../_images/Ringbit_Bricks_Pack_step_06_10.png

../../_images/Ringbit_Bricks_Pack_step_06_11.png

../../_images/Ringbit_Bricks_Pack_step_06_12.png

../../_images/Ringbit_Bricks_Pack_step_06_13.png

../../_images/Ringbit_Bricks_Pack_step_06_14.png

../../_images/Ringbit_Bricks_Pack_step_06_15.png

../../_images/Ringbit_Bricks_Pack_step_06_16.png

../../_images/Ringbit_Bricks_Pack_step_06_17.png

../../_images/Ringbit_Bricks_Pack_step_06_18.png

../../_images/Ringbit_Bricks_Pack_step_06_19.png

../../_images/Ringbit_Bricks_Pack_step_06_20.png

../../_images/Ringbit_Bricks_Pack_step_06_21.png

../../_images/Ringbit_Bricks_Pack_step_06_22.png

../../_images/Ringbit_Bricks_Pack_step_06_23.png

../../_images/Ringbit_Bricks_Pack_step_06_24.png

../../_images/Ringbit_Bricks_Pack_step_06_25.png

../../_images/Ringbit_Bricks_Pack_step_06_26.png

../../_images/Ringbit_Bricks_Pack_step_06_27.png

../../_images/Ringbit_Bricks_Pack_step_06_28.png

../../_images/Ringbit_Bricks_Pack_step_06_29.png

../../_images/Ringbit_Bricks_Pack_step_06_30.png

../../_images/Ringbit_Bricks_Pack_step_06_31.png

../../_images/Ringbit_Bricks_Pack_step_06_32.png

../../_images/Ringbit_Bricks_Pack_step_06_33.png

../../_images/Ringbit_Bricks_Pack_step_06_34.png

../../_images/Ringbit_Bricks_Pack_step_06_35.png

../../_images/Ringbit_Bricks_Pack_step_06_36.png

../../_images/Ringbit_Bricks_Pack_step_06_37.png

../../_images/Ringbit_Bricks_Pack_step_06_38.png

../../_images/Ringbit_Bricks_Pack_step_06_39.png

../../_images/Ringbit_Bricks_Pack_step_06_40.png

../../_images/Ringbit_Bricks_Pack_step_06_41.png

../../_images/Ringbit_Bricks_Pack_step_06_42.png

../../_images/Ringbit_Bricks_Pack_step_06_43.png

../../_images/Ringbit_Bricks_Pack_step_06_44.png

../../_images/Ringbit_Bricks_Pack_step_06_45.png

../../_images/Ringbit_Bricks_Pack_step_06_46.png

***注意:接线时黄色线需要连接在端口上方标有数字(0/1/2)的位置。

../../_images/Ringbit_Bricks_Pack_step_06_47.png

通过下面链接下载PDF文档即可获得详细的搭建步骤图 Github下载

8.5. 软件#


微软makecode

8.6. 编程#


步骤 1#

在MakeCode的代码抽屉中点击“高级”,查看更多代码选项。

../../_images/Ringbit_Bricks_Pack_case_06_03.png

为了给Ringbit_Bricks_Pack套件编程,我们需要添加一个扩展库。在代码抽屉底部找到“扩展”,并点击它。这时会弹出一个对话框,搜索”servo”,然后点击下载这个代码库。

../../_images/Ringbit_Bricks_Pack_case_06_04.png

*注意:*如果你得到一个提示说一些代码库因为不兼容的原因将被删除,你可以根据提示继续操作,或者在项目菜单栏里面新建一个项目。

步骤 2#

当按钮A被按下时,设置连接P1端口的舵机转动180°,暂停300ms,设置连接P1端口的舵机转动90°,暂停1000ms,设置连接P2端口的舵机转动0°,暂停1000ms,设置连接P2端口的舵机转动90°,暂停1000ms,设置连接P1端口的舵机转动0°,暂停300ms,设置连接P1端口的舵机转动90°,暂停500ms,设置连接P2端口的舵机转动180°,暂停1000ms,设置连接P2端口的舵机转动90°,暂停1600ms。

../../_images/Ringbit_Bricks_Pack_case_06_05.png

*注意:*由于我们使用的是360°舵机,而Makecode的servo扩展库是适用于180°舵机的,所以在使用360°舵机的时候,设置舵机转动到0°或者180°会使舵机顺时针转动或者逆时针转动,当设置舵机转动到90°时,舵机停止转动。

程序#

请参考程序连接:https://makecode.microbit.org/_VdHDyY6HJFso

你也可以通过以下网页直接下载程序。

现象#


当按钮A被按下时,投石机执行发射动作并自动上弹。

8.7. 思考#


8.8. 常见问题#


8.9. 相关阅读#