upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions | Protected Attributes
Buzzer Class Reference

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.

int chord[] = { BUZZER_DO, BUZZER_RE, BUZZER_MI,
// create Buzzer instance
upm::Buzzer* sound = new upm::Buzzer(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;

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.

pinNumberBuzzer pin number
~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().

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
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.

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.

Value the volume was set to

Here is the call graph for this function:

std::string name ( )

Returns the name of the sensor.

Name of the sensor
Collaboration diagram for Buzzer:
Collaboration graph

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