#

初始化大脑类#

Brain 是使用以下构造函数创建的:

The brain constructor creates a brain object.

// Create a new object "Brain" with the brain class.
brain Brain;

This Brain object will be used in all subsequent examples throughout this API documentation when referring to brain class methods and attributes.

大脑类有六个预定义属性:

  • [电池](https://test-api.vex.com/exp/home/cpp/Brain/Brain.Battery.html) - 提供有关 EXP Brain 电池的信息,包括容量、电压和电流。

  • 按钮 - 允许您检测按钮按下并为 EXP Brain 上的按钮事件分配功能。

  • 计时器 - 提供测量经过时间并为 EXP Brain 上基于时间的事件分配功能的功能。

  • [屏幕](https://test-api.vex.com/exp/home/cpp/Brain/Brain.Screen.html) - 使您能够在 EXP Brain 的屏幕上显示文本和绘制图像。

  • SDcard - 提供对存储在 EXP Brain 的 SD 卡上的文件的访问。

  • ThreeWirePort - Provides access to 3-Wire Sensors connected to the EXP Brain’s 3-Wire Ports. Each port is identified by a letter (A through H) and can be accessed using the format Brian.ThreeWirePort.X, where X is the port letter. For example, Brian.ThreeWirePort.A refers to the Sensor connected to port A.

类方法#

除了属性之外,Brain 类还提供了几种可以直接使用的方法。

播放声音()#

The playSound(sound) method plays a sound on the Brain.

参数

描述

声音

有效的 soundType

**返回:**无。

// Play a sound of type tada.
Brain.playSound(tada);

播放音调()#

The playTone(tone, volume, duration) method plays a sound on the Brain.

参数

描述

语气

要播放的音调。

体积

播放音调的音量,范围为 0 - 100。

期间

播放音调的时间(以毫秒为单位)。

**返回:**无。

// Play a tone on the Brain.
Brain.playTone(2, 50, 1000);

播放注释()#

该方法可以通过以下方式调用:

The playNote(octave, note) method plays a note in the given octave on the Brain.

参数

描述

八度

要使用的八度。

笔记

要播放的音符。

// Play a note on the Brain.
Brain.playNote(1, 4);

The playNote(octave, note, duration) method plays a note in the given octave on the Brain and waits for the given time before returning.

参数

描述

八度

要使用的八度。

笔记

要播放的音符。

期间

播放音符的持续时间(以毫秒为单位)。

// Play a note on the Brain.
Brain.playNote(1, 4, 200);

播放文件()#

The playFile(filename, volume) method plays a sound file in .wav format on the Brain.

参数

描述

文件名

要播放的声音文件。

体积

音量范围在 0 - 100 之间。

**返回:**无。

// Play the sound file titled "myfile.wav" on the Brain.
Brain.playFile('myfile.wav', 50);

声音关闭()#

The soundOff() method stops any sound that is playing.

**返回:**无。