以 Advanced Weather Sensor (SW01 )配合 OLED DISPLAY(OD01)顯示數據
在早前我們學過利用 Advanced Weather Sensor (SW01 )取得數據,亦學過如何利用OLED DISPLAY(OD01)顯示文字.
這次我們將它們合二為一,一次過由Advanced Weather Sensor (SW01 )取得數據再以OLED DISPLAY(OD01)顯示出來.
所需用料 :
micro:bit x 1
micro:bit bridge IM01 x 1
Advanced Weather Sensor (SW01 ) x 1
OLED DISPLAY(OD01) x 1
xChips Connector x 2
usb cable x 1
micro:bit coding platform : https://makecode.microbit.org/
Advanced Weather Sensor (SW01 ) + OLED DISPLAY(OD01) 接駁方法 :
詳細接駁教學請看此 : 按我

編程教學 :


Ex.1 在OLED DISPLAY(OD01)顯示濕度(humidity)

humidity是一個number , 所以要選取print number

這個是成功的例子, OLED DISPLAY(OD01)上有4組數字是因為 :
編程是寫每按一下BUTTON A , 在新一行就會顯示humidity,
上面的例子因按了四下BUTTON A , 所以有4組數字.
Ex.2 利用不同BUTTON在OLED DISPLAY(OD01)顯示不同數據
在顯示不同數據時, 為免造成混亂 .
做簡單的做法是,按下一個button時顯示一種數據.
再按下另一個button時,上次的數據便消失接著再顯示另一種數據.
為了清除上次的數據 , 我們這次利用了「Clear screen」這個功能.

影片示範 :
Ex3. 一次顯示多個數據
這次我們嘗試一次顯示多種數據

只需要一次過加入幾個print number便可以了.

成功的例子.
Ex4. 顯示數據時加入名稱作分辨
頭3個Ex都只是單純顯示數據,
如果不看回原code是很難知道該數據是代表什麼.
所以在Ex.4 我們將會加入名稱來顯示不同數據.
這次我們不再使用「print newline」,而是使用「at col ___ row ___ 來顯示 !
row 代表在第幾行顯示 ( y axis / 上下)
col 代表在什麼距離顯示 ( x axis / 左右)
每個半型字元 = 5 col , i.e. 1個字母/spacebar/符號...

"humidity : " ⇒ 8個字母 = 5 * 8 ,
3個符號 ( " " + ) + 1 spacebar = 5 * 4 ==> total = 60 col
我們要在 humidity後才顯示數值,所以要再 + 5個col → 65 col
因此 sw01 humidity at col 65

成功的例子.
挑戰1. 同時顯示幾組數據並有名稱作提示
試參考Ex3跟Ex4.