upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Attributes

API for the Buzzer component. More...

Detailed Description

This module defines the Buzzer interface for libbuzzer. This sensor can make different tones when connected to a pin capable of analog pulse-width modulation. It emits sound using a piezoelectric material that vibrates at different frequencies based on the input voltage.

buzzer.jpg
int chord[] = { BUZZER_DO, BUZZER_RE, BUZZER_MI, BUZZER_FA, BUZZER_SOL, BUZZER_LA, BUZZER_SI };
// create Buzzer instance
upm::Buzzer sound(5);
// print sensor name
std::cout << sound.name() << std::endl;
// play each sound (DO, RE, MI, etc...) for .5 seconds, pausing
// for 0.1 seconds between notes
for (int chord_ind = 0; chord_ind < 7; chord_ind++) {
std::cout << sound.playSound(chord[chord_ind], 500000) << std::endl;
upm_delay_ms(100);
}

Public Member Functions

 Buzzer (int pinNumber)
 
 ~Buzzer ()
 
int playSound (int note, int delay)
 
void stopSound ()
 
void setVolume (float vol)
 
float getVolume ()
 
std::string name ()
 

Protected Attributes

std::string m_name
 
buzzer_context m_buzzer
 

Constructor & Destructor Documentation

Buzzer ( int  pinNumber)

Instantiates a Buzzer object.

Parameters
pinNumberBuzzer pin number

Here is the caller graph for this function:

~Buzzer ( )

Buzzer object destructor.

Here is the call graph for this function:

Member Function Documentation

int playSound ( int  note,
int  delay 
)

Plays a tone for a certain amount of time or indefinitely. When delay is not used, the sound can be stopped by calling stopSound().

Parameters
noteNote to play (DO, RE, MI, etc.) or frequency
delayTime in microseconds for which to play the sound; if the value is 0, the sound is played indefinitely
Returns
Note played

Here is the call graph for this function:

void stopSound ( )

Stops the sound currently playing. Should be called when playSound() does not have a delay value.

Here is the call graph for this function:

void setVolume ( float  vol)

Sets the volume for the buzzer, but may affect the sound timbre. Works best with halved values; e.g., 1.0, 0.5, 0.25, etc.

Parameters
volValue to set the volume to, from 0.0 to 1.0

Here is the call graph for this function:

float getVolume ( )

Gets the buzzer volume.

Returns
Value the volume was set to

Here is the call graph for this function:

std::string name ( )
inline

Returns the name of the sensor.

Returns
Name of the sensor

Here is the call graph for this function:

Collaboration diagram for Buzzer:
Collaboration graph
[legend]

The documentation for this class was generated from the following files: