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
- Proporciona información sobre la batería del EXP Brain, incluida la capacidad, la temperatura, el voltaje y la corriente.button
- Le permite detectar pulsaciones de botones y asignar funciones a eventos de botones en el EXP Brain.timer
- Proporciona funcionalidad para medir el tiempo transcurrido y asignar funciones a eventos basados en el tiempo en el EXP Brain.screen
- Le permite mostrar texto y dibujar imágenes en la pantalla del EXP Brain.sdcard
- Proporciona acceso a los archivos almacenados en la tarjeta SD de EXP Brain.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
, wherex
is the port letter. For example,brain.three_wire_port.a
refers 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 |
---|---|
sonido |
Un SoundType válido. |
volumen |
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 |
---|---|
octava |
La octava a utilizar. |
nota |
La nota a tocar. |
duración |
Opcional. La duración en milisegundos durante la cual se reproducirá la nota. |
volumen |
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 |
---|---|
Nombre del archivo |
El archivo de sonido a reproducir. |
volumen |
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.