#

初始化大脑类#

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.

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

  • Battery - Provides information about the EXP Brain’s battery, including capacity, voltage, and current.

  • Button - Allows you to detect button presses and assign functions to button events on the EXP Brain.

  • Timer - Provides functionality to measure elapsed time and assign functions to time-based events on the EXP Brain.

  • Screen - Enables you to display text and draw images on the EXP Brain’s screen.

  • SDcard - Provides access to files stored on the EXP Brain’s SD card.

  • 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.

参数

描述

sound

A valid soundType.

**返回:**无。

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

播放音调()#

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

参数

描述

tone

要播放的音调。

volume

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

duration

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

**返回:**无。

// 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.

参数

描述

octave

要使用的八度。

note

要播放的音符。

// 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.

参数

描述

octave

要使用的八度。

note

要播放的音符。

duration

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

// 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.

参数

描述

filename

要播放的声音文件。

volume

音量范围在 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.

**返回:**无。