Brain#

Initializing the Brain Class#

To use an IQ (2nd gen) Brain in your project, start by initializing it as follows:

# 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 IQ (2nd gen) Brain’s battery, including capacity, temperature, voltage, and current.

  • button - Allows you to detect button presses and assign functions to button events on the IQ (2nd gen) Brain.

  • timer - Provides functionality to measure elapsed time and assign functions to time-based events on the IQ (2nd gen) Brain.

  • screen - Enables you to display text and draw images on the IQ (2nd gen) Brain’s screen.

  • sdcard - Provides access to files stored on the IQ (2nd gen) Brain’s SD card.

Class Methods#

In addition to its attributes, the Brain class provides several methods that can be used directly.

play_sound()#

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

Parameters

Description

sound

A valid SoundType.

Returns: None.

# Play a sound of type TADA.
brain.play_sound(SoundType.TADA)

play_note()#

The play_note(octave, note, duration) method plays a note on the Brain.

Parameters

Description

octave

The octave to use.

note

The note to play.

duration

Optional. The duration in milliseconds to play the note for.

Returns: None.

# Play a note on the Brain.
brain.play_note(1, 4, 200, 50)

sound_off()#

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

Returns: None.