brain#
Initializing the brain Class#
The Brain is created by using the following constructor:
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.
The brain class comes with six pre-defined 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 formatBrian.ThreeWirePort.X
, whereX
is the port letter. For example,Brian.ThreeWirePort.A
refers to the Sensor connected to port A.
Class Methods#
In addition to its attributes, the Brain class provides several methods that can be used directly.
playSound()#
The playSound(sound)
method plays a sound on the Brain.
Parameters |
Description |
---|---|
sound |
A valid SoundType. |
Returns: None.
// Play a sound of type tada.
Brain.playSound(tada);
playTone()#
The playTone(tone, volume, duration)
method plays a sound on the Brain.
Parameters |
Description |
---|---|
tone |
The tone to play. |
volume |
The volume to play the tone at in the range 0 - 100. |
duration |
The time to play the tone for in milliseconds. |
Returns: None.
// Play a tone on the Brain.
Brain.playTone(2, 50, 1000);
playNote()#
This method can be called in the following ways:
The playNote(octave, note)
method plays a note in the given octave on the Brain.
Parameters |
Description |
---|---|
octave |
The octave to use. |
note |
The note to play. |
// 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.
Parameters |
Description |
---|---|
octave |
The octave to use. |
note |
The note to play. |
duration |
The duration in milliseconds to play the note for. |
// Play a note on the Brain.
Brain.playNote(1, 4, 200);
playFile()#
The playFile(filename, volume)
method plays a sound file in .wav format on the Brain.
Parameters |
Description |
---|---|
filename |
The sound file to play. |
volume |
The sound volume in the range 0 - 100. |
Returns: None.
// Play the sound file titled "myfile.wav" on the Brain.
Brain.playFile('myfile.wav', 50);
soundOff()#
The soundOff()
method stops any sound that is playing.
Returns: None.