Module micromelon.sounds
Functions to control the onboard buzzer to play tunes or specific frequencies.
Also helpful definitions for musical notes to their frequency and aliases for different preprogrammed tunes.
Expand source code
"""
Functions to control the onboard buzzer to play tunes or specific frequencies.
Also helpful definitions for musical notes to their frequency and aliases for different preprogrammed tunes.
"""
from ._sounds import *
from ._notes import *
__all__ = ["playNote", "play", "off", "NOTES", "TUNES"]
Functions
def off()- 
Turns the buzzer off (sets frequency to zero Hz)
Returns
None
Expand source code
def off(): """ Turns the buzzer off (sets frequency to zero Hz) Returns: None """ return _rc.writeAttribute(OPTYPE.BUZZER_FREQ, [0]) def play(id)- 
Starts playing a preset tune on the robot
Some preset ids can be found in the TUNES dictionary
Will return immediately and the tune will play until finished or stopped with another commandArgs
id:numberorenum- the tune / song to play
 
Returns
None
Expand source code
def play(id): """ Starts playing a preset tune on the robot Some preset ids can be found in the TUNES dictionary Will return immediately and the tune will play until finished or stopped with another command Args: id (number or enum): the tune / song to play Returns: None """ # Allow use of TUNES enum elements as arguments if isinstance(id, Enum): id = id.value return _rc.writeAttribute(OPTYPE.BUZZER_TUNE, [id]) def playNote(freq, secs=None)- 
Sets the buzzer to the given frequency in Hz
If secs argument is provided, the function will block until that number of seconds has elapsedArgs
freq:positive numberorenum- frequency to play on the buzzer
 secs:positive number- optional number of seconds to wait after setting the frequency
 
Raises
Exception on onvalid arguments
Returns
None
Expand source code
def playNote(freq, secs=None): """ Sets the buzzer to the given frequency in Hz If secs argument is provided, the function will block until that number of seconds has elapsed Args: freq (positive number or enum): frequency to play on the buzzer secs (positive number): optional number of seconds to wait after setting the frequency Raises: Exception on onvalid arguments Returns: None """ # Allow use of NOTES enum as frequency arguments if isinstance(freq, Enum): freq = freq.value if not isNumber(freq) or freq < 0: raise Exception("Note frequency must be a positive number") if secs: secs = restrictTime(secs) # TODO: Is ceil really the right thing to do here? freq = math.ceil(freq) littleEndianFreq = [round(freq) & 0xFF, (round(freq) >> 8) & 0xFF] result = _rc.writeAttribute(OPTYPE.BUZZER_FREQ, littleEndianFreq) if secs: time.sleep(secs) return result 
Classes
class NOTES (value, names=None, *, module=None, qualname=None, type=None, start=1)- 
A collection of standard musical note frequencies
As '#' is not valid in a variable name 's' is used instead
Example: F sharp in the 6th octave would be NOTES.Fs6
B flat in the 4th octave would be NOTES.Bb4Ancestors
- enum.Enum
 
Class variables
var A0var A1var A2var A3var A4var A5var A6var A7var A8var AsBb0var AsBb1var AsBb2var AsBb3var AsBb4var AsBb5var AsBb6var AsBb7var AsBb8var B0var B1var B2var B3var B4var B5var B6var B7var B8var C0var C1var C2var C3var C4var C5var C6var C7var C8var CsDb0var CsDb1var CsDb2var CsDb3var CsDb4var CsDb5var CsDb6var CsDb7var CsDb8var D0var D1var D2var D3var D4var D5var D6var D7var D8var DsEb0var DsEb1var DsEb2var DsEb3var DsEb4var DsEb5var DsEb6var DsEb7var DsEb8var E0var E1var E2var E3var E4var E5var E6var E7var E8var F0var F1var F2var F3var F4var F5var F6var F7var F8var FsGb0var FsGb1var FsGb2var FsGb3var FsGb4var FsGb5var FsGb6var FsGb7var FsGb8var G0var G1var G2var G3var G4var G5var G6var G7var G8var GsAb0var GsAb1var GsAb2var GsAb3var GsAb4var GsAb5var GsAb6var GsAb7var GsAb8
 class TUNES (value, names=None, *, module=None, qualname=None, type=None, start=1)- 
A collection of pre-programmed tunes the robot can play
TUNES.UP = 1
TUNES.DOWN = 2Expand source code
class TUNES(Enum): """ A collection of pre-programmed tunes the robot can play TUNES.UP = 1 TUNES.DOWN = 2 """ UP = 1 DOWN = 2Ancestors
- enum.Enum
 
Class variables
var DOWNvar UP