Sound#

Introduction#

The VEX IQ (2nd generation) Brain can produce audio through its built-in speaker using blocks from the Sound category. These blocks play preloaded sound effects or musical notes.

For the examples below, the constructed Brain includes access to the Sound methods and will be used in all subsequent examples throughout this API documentation when referring to those methods.

Below is a list of all available methods:

Actions – Play sounds from the Brain.

  • play_sound – Play a preset sound from the Brain.

  • play_note – Play a musical note from the Brain.

  • sound_off – Stop the currently playing sound.

Actions#

play_sound#

play_sound plays one of the brain’s built-in sounds.

Usage:
brain.play_sound(sound)

Parameter

Description

sound

The specified sound to play from the brain.

Sound Name

Play Sound

SoundType.ALARM

SoundType.ALARM2

SoundType.DOOR_CLOSE

SoundType.FILLUP

SoundType.HEADLIGHTS_OFF

SoundType.HEADLIGHTS_ON

SoundType.POWER_DOWN

SoundType.RATCHET

SoundType.RATCHET2

SoundType.SIREN

SoundType.SIREN2

SoundType.TADA

SoundType.TOLLBOOTH

SoundType.WRENCH

SoundType.WRONG_WAY

SoundType.WRONG_WAY_SLOW

# Play the TADA sound from the brain
brain.play_sound(SoundType.TADA)

play_note#

play_note plays a specific note for a specific duration in milliseconds.

Usage:
brain.play_note(octave, note, duration)

Parameters

Description

octave

Either the low or high octave:

  • 3 – Low octave
  • 4 – High octave

note

The note to play:

  • 0 – C
  • 1 – D
  • 2 – E
  • 3 – F
  • 4 – G
  • 5 – A
  • 6 – B

duration

Optional. The duration in milliseconds to play the note for, to a max of 500 milliseconds. If no duration is provided, the default duration is 500 milliseconds.

# Play a quarter note C and half note F
brain.play_note(4, 0, 250)
brain.play_note(4, 3, 500)

sound_off#

sound_off stops a sound that is currently playing.

Usage:
brain.sound_off()

Parameters

Description

This method has no parameters.

# Stop any sound that is playing on the brain
brain.play_sound(SoundType.POWER_DOWN)
wait(0.2, SECONDS)
brain.sound_off()