upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Public Member Functions | List of all members

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[] = {
upm_buzzer.javaupm_buzzer.DO,
upm_buzzer.javaupm_buzzer.RE,
upm_buzzer.javaupm_buzzer.MI,
upm_buzzer.javaupm_buzzer.FA,
upm_buzzer.javaupm_buzzer.SOL,
upm_buzzer.javaupm_buzzer.LA,
upm_buzzer.javaupm_buzzer.SI
};
// Instantiate a buzzer on digital pin D5
// print sensor name
System.out.println(sound.name());
for (int i = 0; i < chord.length; i++) {
// play each note for one second
int note = sound.playSound( chord[i], 1000000);
System.out.println(note);
Thread.sleep(100);
}

Public Member Functions

synchronized void delete ()
 
 Buzzer (int pinNumber)
 
int playSound (int note, int delay)
 
void stopSound ()
 
void setVolume (float vol)
 
float getVolume ()
 
String name ()
 

Constructor & Destructor Documentation

Buzzer ( int  pinNumber)

Instantiates a Buzzer object.

Parameters
pinNumberBuzzer pin number

Member Function Documentation

float getVolume ( )

Gets the buzzer volume.

Returns
Value the volume was set to
String name ( )

Returns the name of the sensor.

Returns
Name of the sensor
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 (C, D, E, 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
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
void stopSound ( )

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


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