Top Banner
電子工程系 電腦遊戲設計組 教學(3) 開發mBot應用程式 吳錫修 Feb 17, 2017
17

mBot 教學3 開發mBot應用程式

Jan 14, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: mBot 教學3 開發mBot應用程式

電子工程系應 用 電 子 組電 腦 遊 戲 設 計 組

教學(3)開發mBot應用程式

吳錫修

Feb 17, 2017

Page 2: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

mBlcok 「控制板」選單及「擴充」選單可設定在「機器人模組」下所能使用的硬體控制指令

mBot機器人模組指令 1/6

2 Wu, ShyiShiou Dept. of E.E.

Page 3: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

註記*指令需搭配外接週邊擴充模組

mBot機器人模組指令 2/6

3 Wu, ShyiShiou Dept. of E.E.

*伺服馬達控制

mBot DC馬達控制

mBot DC馬達控制

mBot LED控制

*LED控制

*LED燈帶控制

mBot蜂鳴器控制

mBot起始程式

Page 4: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

mBot機器人模組指令 3/6

4 Wu, ShyiShiou Dept. of E.E.

mBot蜂鳴器控制

*LED陣列(8X16)控制

*4位數7段顯示器控制

*電子快門模組控制

*光線感應器控制

Page 5: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

mBot機器人模組指令 4/6

5 Wu, ShyiShiou Dept. of E.E.

讀取mBot光線感應器數值

檢測mBot按鈕狀態

*只適用連線測試

讀取mBot超音波感測器數值

讀取mBot巡線感測器數值

*讀取搖桿數值

*讀取電位器數值

*讀取聲音感測器數值

*檢測限位開關狀態

Page 6: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

mBot機器人模組指令 5/6

6 Wu, ShyiShiou Dept. of E.E.

*讀取溫度感測器數值

*讀取動作感應器數值

*讀取3軸加速度陀螺儀數值

*讀取溫濕度感測器數值

*讀取火焔感測器數值

*讀取氣體感測器數值

*讀取電子羅盤數值

*檢測觸模感應器狀態

*檢測按鈕模組狀態

Page 7: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

mBot機器人模組指令 6/6

7 Wu, ShyiShiou Dept. of E.E.

檢測mBot紅外線接收器數值

由mBot紅外線發送訊號

讀取mBot紅外線收到的訊號

讀取計時器數值

重置計時器

Page 8: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

mBlock選單命令「編輯>隱藏舞臺模式」,以得到較大程式區空間

隱藏舞臺

8 Wu, ShyiShiou Dept. of E.E.

程式區

Page 9: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

1. 確認mBot為關機狀態

2. 使用USB接線連接mBot與電腦

3. 開啟mBot電源

4. mBlock選單命令「控制板>mBot」

5. mBlock選單命令「連接>序列埠>COM n」

mBot與PC USB連線 1/2

9

接電腦USB port接mBot USB port

Wu, ShyiShiou Dept. of E.E.

Page 10: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

mBlock標題列會顯示「串列埠 已連接」

mBot與PC USB連線 2/2

10 Wu, ShyiShiou Dept. of E.E.

Page 11: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

⼀開始可先使用 做為程式起始指令,方便以連線方式測試程式功能

要上傳到mBot的程式,必須使用 做為程式起始指令,並且只能使用以下模組的指令積木

資料與指令模組 (但不可使用清單資料)

控制模組

運算模組

機器人模組

撰寫mBot程式 1/2

11 Wu, ShyiShiou Dept. of E.E.

Page 12: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

將指令積木拖曳到程式區組合

指令積木右鍵快顯選單命令「新增註解」可為程式加入註解

程式區右鍵快顯選單命令「整理」可重新排列程式

撰寫mBot程式 2/2

12 Wu, ShyiShiou Dept. of E.E.

縮小顯示

回復預設大小

放大顯示

Page 13: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

使用 做為程式起始指令

將mBot直立 (避免測試時mBot亂跑)

mBlock選單命令「連接>更新靭體」

點擊 圖塊,測試程式功能

連線即時測試程式功能

13 Wu, ShyiShiou Dept. of E.E.

Page 14: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

以 取代 指令

上傳程式到mBot離線測試 1/3

14 Wu, ShyiShiou Dept. of E.E.

Page 15: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

點擊⼀下 或mBlock選單命令「編輯>Arduino模式」,切換到Arduino模式

上傳程式到mBot離線測試 2/3

15 Wu, ShyiShiou Dept. of E.E.

Page 16: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

點擊「上傳到Arduino」按鈕,等待「上傳完成」訊息

點擊「返回」按鈕,回mBlock作業

關閉mBot電源,拔除USB接線,離線測試mBot程式

上傳程式到mBot離線測試 3/3

16 Wu, ShyiShiou Dept. of E.E.

Page 17: mBot 教學3 開發mBot應用程式

shap

e th

e fu

ture

mBlock檔案選單

新建專案

打開專案

保存專案

另存為

專案檔案作業

17 Wu, ShyiShiou Dept. of E.E.