#include <unistd.h>
#include <stdio.h>
int main ()
{
if (!speaker)
{
printf("speaker_init() failed\n");
return 1;
}
printf("Exiting\n");
return 0;
}
Go to the source code of this file.
Speaker PWM init. In this mode a PWM pin is used to emit tones (within the capabilities of your PWM hardware). speaker_play_all() and speaker_play_sound() will not operate in this mode. The default frequency is set to 1KHz.
- Parameters
-
pin | Digital PWM capable pin to use |
- Returns
- Device context
Speaker close function
- Parameters
-
Plays all alto notes (lowest notes). This function only operates in GPIO mode.
- Parameters
-
void speaker_play_sound |
( |
const speaker_context |
dev, |
|
|
char |
letter, |
|
|
bool |
sharp, |
|
|
const char * |
vocal_weight |
|
) |
| |
Plays a sound and a note whether it's sharp or not. This function only operates in GPIO mode.
- Parameters
-
dev | Device context |
letter | Character name of the note ('a', 'b', 'c', 'd', 'e', 'f', or 'g') |
sharp | If true, plays a sharp version of the note; otherwise, does not play the note |
vocalWeight | String to determine whether to play a low ("low"), a medium ("med"), or a high ("high") note |
upm_result_t speaker_emit |
( |
const speaker_context |
dev, |
|
|
unsigned int |
freq, |
|
|
unsigned int |
emit_ms |
|
) |
| |
Emit a specific frequency for a given period of time and return. This function only operates when in PWM mode (ie: the speaker context was initialized with speaker_init_pwm()). The frequency is limited to between 50-32000Hz. In addition, the allowable frequencies may be restricted further by the capabilities of your PWM hardware.
- Parameters
-
dev | Device context |
freq | The frequency to emit. Must be between 50 and 32000Hz inclusive. |
emit_ms | The number of milliseconds to emit the frequency. |
- Returns
- UPM result
upm_result_t speaker_set_frequency |
( |
const speaker_context |
dev, |
|
|
unsigned int |
freq |
|
) |
| |
Set a default frequency to be used with speaker_on() and speaker_off(). This function only operates when in PWM mode (ie: the speaker context was initialized with speaker_init_pwm()). The frequency is limited to between 50-32000Hz. In addition, the allowable frequencies may be restricted further by the capabilities of your PWM hardware.
- Parameters
-
dev | Device context |
freq | The frequency to emit. Must be between 50 and 32000Hz inclusive. |
- Returns
- UPM result
Turn the speaker off. This function only operates when in PWM mode (ie: the speaker context was initialized with speaker_init_pwm()).
- Parameters
-