#

初始化大脑类#

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

The brain constructor uses no parameters.

// 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 - 提供有关 IQ(第一代)Brain 电池的信息,包括容量、电压和电流。

  • Button - 允许您检测按钮按下并为 IQ(第一代)Brain 上的按钮事件分配功能。

  • Timer - 提供测量经过时间的功能,并为 IQ(第一代)Brain 上基于时间的事件分配函数。

  • Screen - 使您能够在 IQ(第一代)Brain 的屏幕上显示文本和绘制图像。

类方法#

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

播放声音()#

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

参数

描述

声音

有效的 soundType

**返回:**无。

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

播放注释()#

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

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 Brain.soundOff() method stops any sound that is playing.

**返回:**无。