public class PassiveBuzzer extends PWMComponent
This component then uses a PWM signal to control the output frequency from the buzzer.
Example Datasheet: Passive Buzzer
Example of use: PassiveBuzzerExample
Modifier and Type | Field and Description |
---|---|
static int |
PWM_RANGE_GENERATOR
Range register in the PWM generator.
|
DEFAULT_RPI_PWM_CLOCK_FREQUENCY, PCA9685_PULSE_TICKS, pinNumber
Constructor and Description |
---|
PassiveBuzzer(PCA9685 pca9685,
PCA9685.PCA9685Channel channel)
Constructor for a passive buzzer using a specific PCA9685 to create PWM signals.
|
PassiveBuzzer(PWMPin pin)
Constructor for a passive buzzer using a specific PWM pin from the Raspberry Pi
to create PWM signals.
|
Modifier and Type | Method and Description |
---|---|
void |
playNote(BaseNote baseNote,
int octave,
int millis)
Plays a note, specified from a
BaseNote and an octave,
for a duration of millis milliseconds. |
void |
playTone(double frequency,
int millis)
Plays a tone for a duration of millis milliseconds.
|
void |
pulse(int millis)
Enables the buzzer to play the tone at the currently setted frequency.
|
void |
setFrequency(double frequency)
Sets the frequency played by the buzzer.
|
void |
stop()
Stops the tone played by the buzzer.
|
getType, setPWM, setPWM, setPWMFreq
public static final int PWM_RANGE_GENERATOR
public PassiveBuzzer(PWMPin pin)
pin
- the PWM pin to use to generate the PWM signals.public PassiveBuzzer(PCA9685 pca9685, PCA9685.PCA9685Channel channel)
pca9685
- the PCA9685 to use to generate PWM signals.channel
- the channel on the PCA9685 used to generate the PWM signals.public void playTone(double frequency, int millis)
frequency
- the frequency of the tone.millis
- the duration of the tone.public void playNote(BaseNote baseNote, int octave, int millis)
BaseNote
and an octave,
for a duration of millis milliseconds.baseNote
- the base note to play.octave
- the octave from the base note to play.millis
- the duration of the note to play.public void setFrequency(double frequency)
frequency
- the new frequency played by the buzzer.pulse(int)
public void pulse(int millis)
millis
- the duration of the tone.public void stop()