Skip to content

Commit 6d293a4

Browse files
committed
changed how on() and configureBuzzer() work
-on() no longer takes settings arguments. It soley sets the buzzerActiveRegister to turn on the buzzer -configureBuzzer must be called separately in examples to configure the buzzer -removed silentConfiguration example 9 - because this is done in most other examples already. That is, when you call configureBuzzer(), this does not cause the buzzer to buzz, and so is "silent".
1 parent a62c603 commit 6d293a4

File tree

10 files changed

+189
-134
lines changed

10 files changed

+189
-134
lines changed

examples/Example_02_Buzz_Frequency/Example_02_Buzz_Frequency.ino

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ void setup() {
3939
}
4040

4141
void loop() {
42-
buzzer.on(2730); // resonant frequency is 2.73KHz
42+
// Configure with desired settings
43+
// Resonant frequency is 2.73KHz
44+
buzzer.configureBuzzer(SFE_QWIIC_BUZZER_RESONANT_FREQUENCY);
45+
buzzer.on();
4346
delay(100);
4447

4548
buzzer.off();
4649
delay(1000);
4750

48-
buzzer.on(1000); // try out 1KHz for fun
51+
buzzer.configureBuzzer(1000); // set frequency to 1KHz
52+
buzzer.on();
4953
delay(100);
5054

5155
buzzer.off();

examples/Example_03_Buzz_Duration/Example_03_Buzz_Duration.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ void setup() {
3939
}
4040

4141
void loop() {
42-
buzzer.on(2730, 100); // frequency: 2.73KHz, duration: 100ms
42+
buzzer.configureBuzzer(2730, 100); // frequency: 2.73KHz, duration: 100ms
43+
buzzer.on();
4344
delay(1000);
4445

45-
buzzer.on(1000, 500); // frequency: 1K, duration: 500ms
46+
buzzer.configureBuzzer(1000, 500); // frequency: 1K, duration: 500ms
47+
buzzer.on();
4648
delay(1000);
4749

4850
// Note, we dont' have to call buzzer.off(), because it will automatically turn

examples/Example_04_Buzz_Volume/Example_04_Buzz_Volume.ino

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
44
This example shows how to control the buzzer to sound at different volumes.
55
6-
Note, the "on()" function accepts three arguments, and you must send all three
6+
Note, the "configureBuzzer()" function accepts three arguments, and you must send all three
77
in order to access the volume control.
88
9-
on(frequency, duration, volume);
9+
configureBuzzer(frequency, duration, volume);
1010
1111
It turns the buzzer on and off.
1212
Much like the classic "blink LED sketch" this will buzz
@@ -45,19 +45,23 @@ void setup() {
4545

4646
void loop() {
4747
Serial.println("Volume: MIN (1)");
48-
buzzer.on(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MIN); // frequency: 2.73KHz, duration: 100ms, volume: MIN
48+
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MIN); // frequency: 2.73KHz, duration: 100ms, volume: MIN
49+
buzzer.on();
4950
delay(1000);
5051

5152
Serial.println("Volume: LOW (2)");
52-
buzzer.on(2730, 100, SFE_QWIIC_BUZZER_VOLUME_LOW); // frequency: 2.73KHz, duration: 100ms, volume: LOW
53+
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_LOW); // frequency: 2.73KHz, duration: 100ms, volume: LOW
54+
buzzer.on();
5355
delay(1000);
5456

5557
Serial.println("Volume: MID (3)");
56-
buzzer.on(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MID); // frequency: 2.73KHz, duration: 100ms, volume: MID
58+
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MID); // frequency: 2.73KHz, duration: 100ms, volume: MID
59+
buzzer.on();
5760
delay(1000);
5861

5962
Serial.println("Volume: MAX (4)");
60-
buzzer.on(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MAX); // frequency: 2.73KHz, duration: 100ms, volume: MAX
63+
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MAX); // frequency: 2.73KHz, duration: 100ms, volume: MAX
64+
buzzer.on();
6165
delay(1000);
6266

6367
// Note, we dont' have to use buzzer.off(), because it will automatically turn

examples/Example_06_SaveSettings/Example_06_SaveSettings.ino

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
Qwiic buzzer up. Then you can use the TRIGGER header to cause the buzzer to
2424
buzz at your saved settings.
2525
26-
Note, the "on()" function accepts three arguments:
27-
on(frequency, duration, volume);
26+
Note, the "configureBuzzer()" function accepts three arguments:
27+
configureBuzzer(frequency, duration, volume);
2828
2929
By Pete Lewis @ SparkFun Electronics
3030
December 2023
@@ -61,11 +61,12 @@ void setup() {
6161
// Comment/Un-Comment the following "buzzer.on()" example lines to try different settings:
6262

6363
// "MOMENTARY" SETUP
64-
buzzer.on(1000, 0, SFE_QWIIC_BUZZER_VOLUME_MID); // frequency: 1KHz, duration: 0 (aka forever), volume: MID
64+
buzzer.configureBuzzer(1000, 0, SFE_QWIIC_BUZZER_VOLUME_MID); // frequency: 1KHz, duration: 0 (aka forever), volume: MID
6565

6666
// "ONE-SHOT" Setup (aka adding in a duration amount).
67-
// buzzer.on(1000, 100, SFE_QWIIC_BUZZER_VOLUME_MID); // frequency: 1KHz, duration: 100ms, volume: MID
67+
// buzzer.configureBuzzer(1000, 100, SFE_QWIIC_BUZZER_VOLUME_MID); // frequency: 1KHz, duration: 100ms, volume: MID
6868

69+
buzzer.on();
6970
delay(1000);
7071

7172
Serial.println("Buzzer OFF");

examples/Example_07_Melody/Example_07_Melody.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ void play_melody()
7171
// to calculate the note duration, take one second divided by the note type.
7272
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
7373
int noteDuration = 1000 / noteDurations[thisNote];
74-
buzzer.on(melody[thisNote], noteDuration, SFE_QWIIC_BUZZER_VOLUME_MAX);
74+
buzzer.configureBuzzer(melody[thisNote], noteDuration, SFE_QWIIC_BUZZER_VOLUME_MAX);
75+
buzzer.on();
7576

7677
// to distinguish the notes, set a minimum time between them.
7778
// the note's duration + 30% seems to work well:

examples/Example_08_Sound_Effects/Example_08_Sound_Effects.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
#include <SparkFun_Qwiic_Buzzer_Arduino_Library.h>
7777
QwiicBuzzer buzzer;
7878

79-
#define kBuzzerVolume 4 // loudest!!
80-
//#define kBuzzerVolume 3 // pretty good volume for most things
79+
#define BUZZER_VOLUME 4 // loudest!!
80+
//#define BUZZER_VOLUME 3 // pretty good volume for most things
8181
sfeTkError_t err; // used for checking for errors
8282

8383
void setup() {
@@ -97,7 +97,7 @@ void setup() {
9797
{
9898
Serial.print("Sound Effect: ");
9999
Serial.println(i);
100-
err = buzzer.playSoundEffect(i, kBuzzerVolume);
100+
err = buzzer.playSoundEffect(i, BUZZER_VOLUME);
101101

102102
// Check whether the playSoundEffect() was successful
103103
if (err != kSTkErrOk)

examples/Example_09_SilentConfiguration/Example_09_SilentConfiguration.ino

Lines changed: 0 additions & 57 deletions
This file was deleted.

keywords.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ configureBuzzer KEYWORD2
1818
on KEYWORD2
1919
off KEYWORD2
2020
saveSettings KEYWORD2
21-
setBuzzerActiveReg KEYWORD2
22-
clearBuzzerActiveReg KEYWORD2
2321
playSoundEffect KEYWORD2
2422

2523
#########################################################

0 commit comments

Comments
 (0)