micro:bit + SAM Blocks 基本編程教學(Input)

SAM Studio - Google Chrome

在上篇教學中 , 我們學習了簡單的 micro:bit + RGB  的編程 , 這次將教大家配合 SAM Labs 的 Input Blocks 進行編程 , 創造一些簡單又有趣的小專題!

讀取 Proximity Sensor 的數值 , 並利用 micro:bit LED 顯示

SAM Studio - Google Chrome

在 ADD New Device 中按下「Proximity Sensor」以加入它的虛擬 Blocks 及 extension block。

編程教學 :

SAM Studio - Google Chrome

由於需要顯示數字 , 我們需要利用到 display " word " 先把它拖出來

創建一個 variable 來顯示數值

SAM Studio - Google Chrome
SAM Studio - Google Chrome

在 「Variables」中創建一個 variabale , " Create variable .... " , 然後輸入 vaiable的名稱 這次是 : Proximity

SAM Studio - Google Chrome

我們設定了按下 micro:bit A 才顯示 Proximity sensor 的數值 , 因此設定 「Proximity」 Variable 需同時放中 micro:bit A pressed 內!

SAM Studio - Google Chrome

把 variable 「Proximity」設為「get Proximity Sensor Value」, 這樣便能顯示Sensor的數值

SAM Studio - Google Chrome

使用 Display varibale 「Proximity」以在 micro:bit LED 上顯示數值。

測試編程 :

同樣先按下「RUN」 !

SAM Studio - Google Chrome

調整好要顯示的距離(proximity)後,便按下 micro:bit 的 A 制來顯示數值 eg 31 。