upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
Include dependency graph for buzzer.h:

API Description

/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <upm_utilities.h>
#include <buzzer.h>
int
main(int argc, char **argv)
{
int chord[] = { BUZZER_DO, BUZZER_RE, BUZZER_MI,
BUZZER_FA, BUZZER_SOL, BUZZER_LA,
BUZZER_SI };
// create Buzzer context, using PWM pin 5
if (!sound)
{
printf("buzzer_init() failed\n");
return 1;
}
printf("Playing...\n");
// 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++)
{
buzzer_play_sound(sound, chord[chord_ind], 500000);
printf("%d\n", chord[chord_ind]);
upm_delay_ms(100);
}
printf("Exiting...\n");
buzzer_close(sound);
return 0;
}

Go to the source code of this file.

Data Structures

struct  _buzzer_context
 

Functions

buzzer_context buzzer_init (int pin)
 
void buzzer_close (buzzer_context dev)
 
upm_result_t buzzer_play_sound (const buzzer_context dev, int note, int delay)
 
upm_result_t buzzer_stop_sound (const buzzer_context dev)
 
void buzzer_set_volume (const buzzer_context dev, float vol)
 
float buzzer_get_volume (const buzzer_context dev)
 

Typedefs

typedef struct _buzzer_contextbuzzer_context
 

Function Documentation

buzzer_context buzzer_init ( int  pin)

Initialize a buzzer context.

Parameters
pinBuzzer pin number (pwm capable)
Returns
buzzer device context

Here is the call graph for this function:

void buzzer_close ( buzzer_context  dev)

Buzzer object destructor.

Parameters
devDevice context.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t buzzer_play_sound ( const buzzer_context  dev,
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
devDevice context.
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
UPM result

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t buzzer_stop_sound ( const buzzer_context  dev)

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

Parameters
devDevice context.
Returns
UPM result

Here is the caller graph for this function:

void buzzer_set_volume ( const buzzer_context  dev,
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
devDevice context.
volValue to set the volume to, from 0.0 to 1.0

Here is the caller graph for this function:

float buzzer_get_volume ( const buzzer_context  dev)

Gets the buzzer volume.

Parameters
devDevice context.
Returns
Value the volume was set to

Here is the caller graph for this function:

Typedef Documentation

typedef struct _buzzer_context * buzzer_context

Device context