Skip to content

Commit f19864f

Browse files
committed
filled in/finished the readme sections
1 parent 90a6654 commit f19864f

File tree

1 file changed

+103
-3
lines changed

1 file changed

+103
-3
lines changed

README.md

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,114 @@ Looking for the board that matches this library - pick up a [SparkFun Qwiic Buzz
2323

2424
This library provides an interface that enables the following functionality when a SparkFun Qwiic Buzzer breakout board:
2525

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
2831

2932

3033
## General Use
34+
The following outlines the general use of the library in an Arduino Sketch.
3135

32-
***TODO***
36+
### Declaration
3337

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+
void loop() {
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.
86+
87+
~~~cpp
88+
void loop() {
89+
// Configure with desired settings
90+
// Resonant frequency is 2.73KHz
91+
buzzer.configureBuzzer(SFE_QWIIC_BUZZER_RESONANT_FREQUENCY);
92+
buzzer.on();
93+
delay(100);
94+
95+
buzzer.off();
96+
delay(1000);
97+
98+
buzzer.configureBuzzer(1000); // set frequency to 1KHz
99+
buzzer.on();
100+
delay(100);
101+
102+
buzzer.off();
103+
delay(1000);
104+
}
105+
~~~
106+
107+
#### Buzz Duration
108+
109+
The buzz duration is set by adding a timing value after the frequency to the ```configureBuzzer()``` method.
110+
111+
~~~cpp
112+
buzzer.configureBuzzer(2730, 100); // frequency: 2.73KHz, duration: 100ms
113+
~~~
114+
115+
#### Volume
116+
117+
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+
~~~
34134
## Examples
35135

36136
The following examples are provided with the library

0 commit comments

Comments
 (0)