Cerebro#
Inicializando la clase Brain#
Para utilizar EXP Brain en su proyecto, comience inicializándolo de la siguiente manera:
# 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.
La clase Brain viene con seis atributos predefinidos:
battery- Provides information about the EXP Brain’s battery, including capacity, temperature, 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.three_wire_port- 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 formatbrain.three_wire_port.x, wherexis the port letter. For example,brain.three_wire_port.arefers to the Sensor connected to port A.
Atributos
Métodos de clase#
Además de sus atributos, la clase Brain proporciona varios métodos que se pueden utilizar directamente.
reproducir_sonido()#
The brain.play_sound(sound, volume) command plays a sound on the Brain.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
Opcional. El volumen del sonido, máximo es 100. |
Devoluciones: Ninguna.
# Play a sound of type TADA.
brain.play_sound(SoundType.TADA)
reproducir_nota()#
The brain.play_note(octave, note, duration, volume) command plays a note on the Brain.
Parámetros |
Descripción |
|---|---|
|
La octava a utilizar. |
|
La nota a tocar. |
|
Opcional. La duración en milisegundos durante la cual se reproducirá la nota. |
|
Opcional. El volumen del sonido. El máximo es 100. |
Devoluciones: Ninguna.
# Play a note on the Brain.
brain.play_note(1, 4, 200, 50)
reproducir_archivo()#
The brain.play_file(filename, volume) command plays a sound file in .wav format on the Brain.
Parámetros |
Descripción |
|---|---|
|
El archivo de sonido a reproducir. |
|
Opcional. El volumen del sonido, máximo es 100. |
Devoluciones: Ninguna.
# Play the sound file titled "myfile.wav" on the Brain.
brain.play_file('myfile.wav', 50)
sonido_apagado()#
The brain.sound_off() command stops any sound that is playing.
Devoluciones: Ninguna.
# Turn off the sound on the Brain.
brain.sound_off()
el sonido está activo()#
The brain.sound_is_active() command checks whether a sound is playing.
Returns: True if a sound is playing. False if a sound is not playing.
duración_del_sonido()#
The brain.sound_duration() command gets the total duration of the currently playing sound.
Devuelve: La duración en milisegundos.
sonido_restante()#
The brain.sound_remaining() command gets the remaining duration of the currently playing sound.
Devuelve: La duración en milisegundos.