声音#

介绍#

VEX IQ(第二代)大脑可以使用“声音”类别的积木,通过其内置扬声器发出声音。这些积木可以播放预加载的音效或音符。

对于以下示例,构造的 Brain 包含对 Sound 方法的访问权限,并且在本 API 文档的所有后续示例中引用这些方法时都将使用它。

以下是所有可用方法的列表:

动作——播放来自大脑的声音。

  • playSound – Play a preset sound from the Brain.

  • playNote – Play a musical note from the Brain.

行动#

playSound#

playSound plays one of the Brain’s built-in sounds.

Usage:
Brain.playSound(sound);

参数

描述

sound

从大脑播放的指定声音。

声音名称

播放声音

alarm

alarm2

doorClose

fillup

headlightsOff

headlightsOn

powerDown

ratchet

ratchet2

siren

siren2

tada

tollBooth

wrench

wrongWay

wrongWaySlow

// Example coming soon

playNote#

playNote plays a musical note from the Brain.

Usage:
Brain.playNote(octave, note, duration);

参数

描述

octave

The integer that represents the octave the note is played in:

  • 1 to 3 – low octave
  • 4 to 7 – high octave

note

The note to play:

  • 0 – C
  • 1 – D
  • 2 – E
  • 3 – F
  • 4 – G
  • 5 – A
  • 6 – B

duration

可选。音符播放的时长(以毫秒为单位),最长为 500 毫秒。如果未提供时长,则默认时长为 500 毫秒。

// Example coming soon