Top Banner
電子工程系 電腦遊戲設計組 教學(6) 光感測器與LED應用 吳錫修 Feb 17, 2017
18

mBot 教學6 光感測器應用

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 教學6 光感測器應用

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

教學(6)光感測器與LED應用

吳錫修

Feb 17, 2017

Page 2: mBot 教學6 光感測器應用

shap

e th

e fu

ture

也稱光電二極體,photodiode無光照時,只有很小的逆向飽和漏電流 (暗電流),此時光敏二極體截止。當受到光照時,逆向飽和電流大大增加,形成光電流

photodiode是透明封裝,可加上黑色套管,降低側面受光而影響光感測器讀值

光敏二極體原理

2 Wu, ShyiShiou Dept. of E.E.

Page 3: mBot 教學6 光感測器應用

shap

e th

e fu

ture

mBot光感測器

3

LightSensor

Wu, ShyiShiou Dept. of E.E.

Page 4: mBot 教學6 光感測器應用

shap

e th

e fu

ture

1. 連接mBot與PC

2. mBlock選單命令連接>更新韌體

3. 編輯程式區塊

4. 測試

手掌在光感測器上方移動,觀察數值變化情形

測試光感測器傳回值

4 Wu, ShyiShiou Dept. of E.E.

Page 5: mBot 教學6 光感測器應用

shap

e th

e fu

ture

控制指令

讀取光線感應器偵測值,傳回值0~1023,受光愈強,數值愈大

搭配運算指令及控制指令使用

mBot光感測器控制

5 Wu, ShyiShiou Dept. of E.E.

Page 6: mBot 教學6 光感測器應用

shap

e th

e fu

ture

功能要求

光感測器讀值大於200時,mBot開始前進

mBot受光愈強,mBot速度愈快

需依環境光狀態調整cds臨界值

光驅動練習 1/2

6 Wu, ShyiShiou Dept. of E.E.

Page 7: mBot 教學6 光感測器應用

shap

e th

e fu

ture

參考程式

建立cds變數

光驅動練習 2/2

7 Wu, ShyiShiou Dept. of E.E.

Page 8: mBot 教學6 光感測器應用

shap

e th

e fu

ture

mBot 全彩LED

8

RGB LED2

RGB LED1

Wu, ShyiShiou Dept. of E.E.

Page 9: mBot 教學6 光感測器應用

shap

e th

e fu

ture

發光二極體 (Light-emitting diode,LED) 是⼀種能發光的半導體電子元件

單色 LED

紅外線 、紅、橙、黃、綠、藍、紫、紫外線

LED原理 1/2

9 Wu, ShyiShiou Dept. of E.E.

Page 10: mBot 教學6 光感測器應用

shap

e th

e fu

ture

RGB LED

可分別控制紅、綠、藍LED發光強度,混合出全彩效果 (16,777, 216 種顏色變化)

LED原理 2/2

10 Wu, ShyiShiou Dept. of E.E.

Page 11: mBot 教學6 光感測器應用

shap

e th

e fu

ture

控制指令

mBot RGB LED控制

11

最亮

不亮

RGB LED2RGB LED1

Wu, ShyiShiou Dept. of E.E.

Page 12: mBot 教學6 光感測器應用

shap

e th

e fu

ture

功能要求

使左右LED隨機顯示不同顏色

每0.2秒變換顏色

全彩霓虹燈練習 1/2

12 Wu, ShyiShiou Dept. of E.E.

Page 13: mBot 教學6 光感測器應用

shap

e th

e fu

ture

參考程式

建立R、G、B變數

全彩霓虹燈練習 2/2

13 Wu, ShyiShiou Dept. of E.E.

Page 14: mBot 教學6 光感測器應用

shap

e th

e fu

ture

功能要求

按下按鈕後,mBot前進

當mBot進入隧道時放慢速度,點亮RGB LED燈

當mBot離開隧道時回復速度,關閉LED燈

設計注意事項:

1. 要依據環境光線強度調整光感測器臨界值

2. 由於光感測器側面沒有遮蔽,點亮RGB LED燈時,光感測器會接收到RGB LED光源

隧道自動照明練習 1/2

14 Wu, ShyiShiou Dept. of E.E.

Page 15: mBot 教學6 光感測器應用

shap

e th

e fu

ture

參考程式

建立cds變數

隧道自動照明練習 2/2

15 Wu, ShyiShiou Dept. of E.E.

Page 16: mBot 教學6 光感測器應用

shap

e th

e fu

ture

功能要求

按下按鈕後,mBot前進

每3秒讓mBot隨機左轉或右轉

轉彎前閃爍LED方向燈,每0.2秒紅色亮、滅閃爍2次

mBot轉彎方向燈練習 1/3

16 Wu, ShyiShiou Dept. of E.E.

Page 17: mBot 教學6 光感測器應用

shap

e th

e fu

ture

參考程式

mBot轉彎方向燈練習 2/3

17 Wu, ShyiShiou Dept. of E.E.

Page 18: mBot 教學6 光感測器應用

shap

e th

e fu

ture

mBot轉彎方向燈練習 3/3

18 Wu, ShyiShiou Dept. of E.E.