顯示具有 WuKong 標籤的文章。 顯示所有文章
顯示具有 WuKong 標籤的文章。 顯示所有文章

2024年1月28日 星期日

micro:bit -悟空板(WuKong):土壤溼度(Soil Humidity)感測器測試 (MakeCode版)

準備材料:

  1. micro:bit主板 x 1
  2. USB 連接線 x 1
  3. GVS接腳的LED x1
  4. GVS接腳的土壤溼度計 x 1
  5. 悟空板 WuKong x 1

接線:

  1. LED接在P15
  2. 土壤溼度感測器接在P0

程式:





執行結果:



micro:bit -悟空板(WuKong):馬達測試 (MakeCode版)

悟空板介紹:Wukong Breakout Board 悟空擴充板

馬達連接接腳

程式編輯:https://makecode.microbit.org/#editor

安裝悟空板的驅動


選擇上圖wukong選項。

範例一、馬達測試:


執行結果:


範例二、按鈕控制


執行結果:




micro:bit -悟空板(WuKong):NeoPixel測試 (Python版)

範例一:分別以紅色、綠色、藍色、白色點亮悟空板上的四顆燈 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Imports go at the top
from microbit import *
import neopixel
np = neopixel.NeoPixel(pin16, 4)


# Code in a 'while True:' loop repeats forever
while True:
    np[0] = (255, 0, 0)
    np[1] = (0, 255, 0)
    np[2] = (0, 0, 255)
    np[3] = (255, 255, 255)
    np.show()

執行結果:

範例二:同範例一,顯示資料用串列變數來儲存

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Imports go at the top
from microbit import *
import neopixel
np = neopixel.NeoPixel(pin16, 4)

leds=[(255,0,0), (0,255,0), (0,0,255), (255,255,255)]
# Code in a 'while True:' loop repeats forever
while True:
    np[0] = leds[0]
    np[1] = leds[1]
    np[2] = leds[2]
    np[3] = leds[3]
    np.show()

執行結果同上題

範列三:每隔0.5秒燈色旋轉

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Imports go at the top
from microbit import *
import neopixel
np = neopixel.NeoPixel(pin16, 4)
i = 0
leds=[(255,0,0), (0,255,0), (0,0,255), (255,255,255)]
# Code in a 'while True:' loop repeats forever
while True:
    np[0] = leds[i]
    np[1] = leds[(i+1)%4]
    np[2] = leds[(i+2)%4]
    np[3] = leds[(i+3)%4]
    np.show()
    sleep(500)
    i=(i+1)%4

執行結果:


範例四、用迴圈改寫程式

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Imports go at the top
from microbit import *
import neopixel
np = neopixel.NeoPixel(pin16, 4)
i = 0
leds=[(255,0,0), (0,255,0), (0,0,255), (255,255,255)]
# Code in a 'while True:' loop repeats forever
while True:
    for j in range(4):
        np[j] = leds[(i+j)%4]
    np.show()
    sleep(500)
    i=(i+1)%4

執行結果:
同範例三

micro:bit -悟空板(WuKong):NeoPixel測試 (MakeCode版)

悟空板介紹:Wukong Breakout Board 悟空擴充板

在悟空板上Pin 16接上四顆LED,分別是LED1, LED2, LED3, 和LED4,如下圖。

程式編輯:https://makecode.microbit.org/#editor


在上圖右下方,點選Extensions選項。


點選上圖左方 neopixel的選項,就可以安裝驅動程式。

範例一、依序點亮


執行結果:


範例二、每隔0.5秒循環


執行結果:

範例三、依照聲音大小用長條圖來改變燈條燈數



執行結果: