Sound Block Icon of block

聲音指令


Sound Block

聲音指令負責播放聲音檔案或是音調。在編寫音樂程式時可以多個指令組合,而每個指令會播放不同的音調。
You can use this block to play a sound file or a single tone. To compose a melody of tones, arrange several sound blocks in a row with each set to play different tones.

如果點選"等待完成"功能,則程式會聲音檔案撥完前才會執行下一個指令.若沒有勾選,則會在邊執行下一個動作邊撥放聲音。
If you select “Wait for completion” in the configuration panel, the sound file or tone will finish playing before the program moves on to the next block. With this item unchecked, the sound file or tone will continue to play while the next block of your program proceeds.

重複指令會不斷的撥放聲音.
Choosing “Repeat” will cause a sound file to play again and again.

Image of Sound block, default settings

  1. 此圖示表示播放的是聲音檔或是音調。
    This icon shows whether the block will play a sound file or a tone.
  2. 此圖示表示聲音的開始或撥放。
    This icon shows whether the block will start or stop playing a sound.
  3. 此圖示表示音量。橘色的四格全滿代表最大音量。
    This icon shows the block’s volume. An icon with four orange bars is set to the loudest volume.
  4. 從其他指令的資料集線器所連結過來的資料線會影響聲音指令的參數.(參閱下方的資料集線器說明)
    You can drag data wires from other blocks to this block’s data hub that will affect the Sound block’s properties. (See the Data Hub section below for more information.)

設定聲控指令
Configuring the Sound Block

Image of the configuration pane for the Sound block with sound file chosen

Image of the configuration pane for the Sound block with tone selected

  1. 狀態參數表示撥放聲音檔或是組合的音調.
    The Action property radio buttons let you choose to play a sound file or a tone that you’ll compose.
  2. 撥放或停止聲音檔.
    Choose to play or stop playing a sound file or tone.
  3. 滑桿設定音量.或輸入音量數值.
    Set the volume using the slider. Use the text field to type in an exact value.

若撥放聲音檔(如上述的第一個參數面板),提供下列的參數控制.
If you choose to play a sound file (as in the first configuration panel above), you’ll be able to set the following additional properties:

  1. "功能"參數會不停地重複撥放聲音檔,勾選時"等待完成"的選項就沒有作用.
    The Function property will let you set the sound file to repeat so that it plays again and again without stopping. The “Wait for completion” option will be grayed out and no longer available.
  2. "檔案"參數可以選擇撥放的檔名,依照字母順序列在表中.聲音檔是存在硬碟中LEGO MINDSTORMS軟體的聲音檔案夾裡,點選每個檔案可以聽到內容.
    The File property will let you choose the sound file by its name. You’ll see an alphabetical list of available sounds. These are stored in the Sound Files folder of the LEGO MINDSTORMS software on your hard drive. Click on each name to hear it played.
  3. 如果勾選"等待完成"選項,程式會撥放完聲音檔後才執行下一個指令,如果沒有勾選,聲音檔就會隨著下個指令的執行撥放.若下個指令也是聲音指令,則會自動停止前一個聲音檔而撥放新的聲音檔.
    If you check the “Wait for Completion” checkbox, the sound file will play to its end before allowing the program to move on the next block. With the box unchecked, the sound file will play while the next block in the program proceeds. If the next block is another Sound block, the first Sound file will stop automatically and the new Sound file will play.

若撥放音調(如上述的第二個參數面板),提供下列的參數控制.
If you choose to play a tone (as in the second configuration panel above), you’ll be able to set the following additional properties:

  1. "音符"參數可以發出一個組合的音符,小琴鍵圖樣顯示出三個八度音階.而用滑鼠點選的琴鍵或是用鍵盤輸入的音符會出現在上方的文字欄位.而旁邊的碼錶式指定音符的撥放時間(以十之一秒為單位).
    The Note property will allow you to compose a tone to play when the Sound block is activated. The small keyboard represents three octaves of the musical scale. The text field above the keyboard will display the note that is either pressed on this keyboard with your mouse or typed in using your computer’s keyboard. The input box next to the stopwatch is for specifying the duration of the note in 1/10s of a second.
  2. 如果勾選"等待完成"選項,程式會撥放完音調後才執行下一個指令,如果沒有勾選,音調檔就會隨著下個指令的執行撥放.
    If you check the “Wait for Completion” checkbox, your tone will play to its end before allowing your program to move on the next block in your program. With the box unchecked, your tone will play while the next block of your program proceeds.

設定聲控指令的資料集線器
Configuring the Sound block’s Data Hub

用資料線可以任意地用來控制聲音指令.(從其他指令的資料集線器到聲控指令的資料集線器).
You can control the Sound block dynamically by connecting data wires (from other blocks’ data hubs) to the Sound block’s data hub.

把指令放在工作區上後,可以按圖示的左下角來打開資料集線器.
Open a block’s data hub by clicking the tab at the lower left edge of the block after it has been placed on the work area.

Image showing unopened tab on a generic block

連接到集線器左邊連接埠的資料線是屬於負責傳遞資料進入指令中,而要從指令送出資料時,則須從集線器的右邊連接埠連接資料線.
Data wires carrying input information to a block are connected to the plugs on the left side of its data hub. Data wires carrying output information are connected to the plugs on the right side.

Image of data wires

[A]輸入連接埠 [A] Input plug
[B]輸出連結部 [B] Output plug
[C]數字資料線(黃) [C] Number data wire (yellow)
[D]邏輯資料線(綠) [D]Logic data wire (green)
[E]文字資料線(橘) [E]Text data wire (orange)
[F]無效資料線(灰) [F]Broken data wire (gray)

資料由輸入端傳至傳出端
Passing data from the input plug to the output plug

如果輸入連接埠有對應的輸出連接埠(請參閱 A 以上)時,那麼輸入的資料就會原封不動地傳遞到輸出連接埠.在這樣的情況下, 如果輸入連接埠連著資料線,那麼就只能使用輸出連結埠來做連結. 也就是說,當連結輸出連接線到這樣的輸出連接埠,而不透過相對應的輸入資料線時,就會讓該輸出連接線呈現無效的狀態.
If an input plug has a corresponding output plug (see A above), the input data will pass through from the input plug to the output plug without being changed. In this case, you can only use the output plug if the input plug is connected to an input data wire; connecting an output data wire to such an output plug without a connected input data wire will cause the output data wire to be “broken” (and colored gray).

特定的資料型態
Data wires carry specific types of data

每條資料線都負責傳送特定資料.例如,一條從邏輯連接埠拉出的資料線則只能連結到另一個同屬邏輯連接埠的集線器上.
Each data wire carries a specific type of data between blocks. For example, if a data wire is dragged from a logic plug on a block’s data hub, it can only be connected to a logic plug on another block’s data hub. The chart below shows what kind of data each plug can accept or send out.

資料線顏色
Data wire colors

資料線依照特定的顏色作識別:黃色資料線傳送數值資料、綠色資料線傳送邏輯資料(真/偽)及橘色資料線傳送文字資料
Data wires are identified with specific colors: wires carrying number data are colored yellow, wires carrying logic data are colored green, and wires carrying text data are colored orange.

無效的資料線
“Broken” data wires

如果資料線連結到錯誤資料型態的連接埠時,則該資料線會呈現斷線無效狀態並以灰色表示.而有無效的資料線存在就無法下載程式.
If you try to connect a data wire to a plug of the wrong data type, the data wire will be broken (and colored gray). You will not be able to download your program if a data wire is broken.

點選無效的資料線時,在工作區右下方的幫助視窗中會看到無效的原因.
If you click a broken wire you can read why it is broken in the small help window in the lower right corner of the work area.

資料必須在連接埠的限制範圍內
Data must be within the possible range of the plug

如果資料線傳輸該連接埠資料範圍之外的資料時,該指令不是忽略資料就是轉成合理範圍內的資料.對那些只能接收少量輸入值的連接埠來說(例如,0,1,或2),該連結埠就會忽略超出範圍的數值.
If an input data wire transmits a value outside the possible range of the plug it is connected to, the block will either ignore the value or change it to a value within its range. For plugs that allow just a few input values (example: just 0, 1, or 2), the plug will ignore the input if a value arrives outside its range.

而對那些可以接收大量範圍輸入值(例如: 0~100)的連接埠來說,該連接埠就會將數值轉成可接受的範圍. 例如, 移動指令的動力連接埠接收到150的輸入值時,那麼移動指令就會轉成100(也就是動力連接埠的範圍內).
For plugs that accept larger input ranges (example: 0 – 100), the plug will force any input outside its range to fit. For example, if a Move block’s Power plug receives an input value of 150, the block will change the input value to 100 (i.e., a number within the Power plug’s range).

下表列出本資料集線器中各連接埠的特性
This chart shows the different characteristics of the plugs on the Sound block’s data hub:

  連接埠
Plug
資料型態
Data Type
資料範圍
Possible Range
資料意義
What the Values Mean
連接埠例外說明
This Plug is Ignored When...
Port 狀態
Action
數值
Number
0 - 1 0=聲音檔, 1=音調
0 = Sound file, 1 = Tone
 
Port 檔案名稱
Filename
文字
Text
最多15個字元
15 character maximum
撥放的聲音檔案名稱
Filename of sound file to play
狀態=音調
Action = Tone
Port 音調頻率
Tone Frequency
數值
Number
0 - 65535 以赫茲來表示頻率.NXT內建的喇叭可以撥放264到4000赫茲之間的聲音.
Tone frequency in Hertz. The NXT's internal speaker can play back frequencies between approximately 264 and 4000 Hertz.
狀態=聲音檔
Action = Sound file
Port 控制
Control
數置
Number
0 - 1 0=撥放,1=停止
0 = Play, 1 = Stop
 
Port 音量
Volume
數值
Number
0 - 100 音量.特別注意:共有五種音量(0,25,50,75,100).介於之間的音量會向下調整.
Sound volume. Special note: there are really only 5 sound levels (0, 25, 50, 75, and 100); numbers in between are rounded downwards.
狀態=聲音檔
Action = Sound file
Port 執行時間
Duration
數值
Number
0 - 65535 音調撥放時間(毫秒)
Tone duration in milliseconds
狀態=聲音檔
Action = Sound file