You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+103-3Lines changed: 103 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -23,14 +23,114 @@ Looking for the board that matches this library - pick up a [SparkFun Qwiic Buzz
23
23
24
24
This library provides an interface that enables the following functionality when a SparkFun Qwiic Buzzer breakout board:
25
25
26
-
****TODO***
27
-
*
26
+
* Turn the buzzer on and off
27
+
* Adjust the buzzers frequency and duration
28
+
* Control the the volume of the buzzer
29
+
* Play sound effects on the buzzer
30
+
* Change the I2C address to enable the use of multiple buzzers on one device
28
31
29
32
30
33
## General Use
34
+
The following outlines the general use of the library in an Arduino Sketch.
31
35
32
-
***TODO***
36
+
### Declaration
33
37
38
+
At the start of your sketch, the library header file is included using the following statement:
39
+
40
+
~~~cpp
41
+
#include<SparkFun_Qwiic_Buzzer_Arduino_Library.h>
42
+
~~~
43
+
44
+
Before the arduino ```setup()``` function, create a Buzzer object in your file with the following declaration:
45
+
46
+
~~~c
47
+
QwiicBuzzer buzzer; // its a buzzer
48
+
~~~
49
+
50
+
51
+
### Initialization
52
+
53
+
In the Arduino ```setup()``` function, initialize the buzzer by calling the begin method. This method is called after the Arduino `Wire` (I2C) library is initialized.
54
+
55
+
~~~cpp
56
+
//check if buzzer will connect over I2C
57
+
if (buzzer.begin() == false) {
58
+
Serial.println("Device did not connect! Freezing.");
59
+
while (1);
60
+
}
61
+
~~~
62
+
63
+
The begin method returns true if the buzzer is connected and available, and false if it is not. If a value of *false* is returned in the above example, the sketch execution is halted.
64
+
65
+
### Usage
66
+
67
+
#### On/Off
68
+
69
+
Turn the buzzer on and off as shown in the following loop example:
70
+
71
+
~~~cpp
72
+
voidloop() {
73
+
buzzer.on();
74
+
75
+
delay(1000);
76
+
77
+
buzzer.off();
78
+
79
+
delay(1000);
80
+
}
81
+
~~~
82
+
83
+
#### Frequency Control
84
+
85
+
The buzzer frequency is controlled using the ```configureBuzzer()``` method.
The buzz volume is an additional optional parameter to the ```configureBuzzer()``` method.
118
+
119
+
~~~cpp
120
+
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MIN); // frequency: 2.73KHz, duration: 100ms, volume: MIN
121
+
...
122
+
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MAX); // frequency: 2.73KHz, duration: 100ms, volume: MAX
123
+
~~~
124
+
125
+
#### Sound Effects
126
+
127
+
The buzzer has a collection of sound effects included in this library. These are started by using the ```playSoundEffect()``` method, providing the number of the sound effect to play.
128
+
129
+
Playing sound effect 1:
130
+
131
+
~~~cpp
132
+
err = buzzer.playSoundEffect(1, BUZZER_VOLUME);
133
+
~~~
34
134
## Examples
35
135
36
136
The following examples are provided with the library
0 commit comments