Skip to content

Commit 27f8cfc

Browse files
committed
lots of little stuff + silent config example
-removed Serial println debug -fixed type in address example -fixed address range comment -utilized dataLength more properly in configureBuzzer -created initial address variable in changeAddress example -created silent configuration example to showcase config and set active reg functions. -changed "acknowledged" to "connected" in print statements.
1 parent eace09c commit 27f8cfc

File tree

11 files changed

+90
-31
lines changed

11 files changed

+90
-31
lines changed

examples/Example_01_Buzz/Example_01_Buzz.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ void setup() {
2828
Serial.println("Qwiic Buzzer Example_01_Buzz");
2929
Wire.begin(); //Join I2C bus
3030

31-
//check if buzzer will acknowledge over I2C
31+
//check if buzzer will connect over I2C
3232
if (buzzer.begin() == false) {
33-
Serial.println("Device did not acknowledge! Freezing.");
33+
Serial.println("Device did not connect! Freezing.");
3434
while (1);
3535
}
36-
Serial.println("Buzzer acknowledged.");
36+
Serial.println("Buzzer connected.");
3737
}
3838

3939
void loop() {

examples/Example_02_Buzz_Frequency/Example_02_Buzz_Frequency.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ void setup() {
3030
Serial.println("Qwiic Buzzer Example_02_Buzz_Frequency");
3131
Wire.begin(); //Join I2C bus
3232

33-
//check if buzzer will acknowledge over I2C
33+
//check if buzzer will connect over I2C
3434
if (buzzer.begin() == false) {
35-
Serial.println("Device did not acknowledge! Freezing.");
35+
Serial.println("Device did not connect! Freezing.");
3636
while (1);
3737
}
38-
Serial.println("Buzzer acknowledged.");
38+
Serial.println("Buzzer connected.");
3939
}
4040

4141
void loop() {

examples/Example_03_Buzz_Duration/Example_03_Buzz_Duration.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ void setup() {
3030
Serial.println("Qwiic Buzzer Example_03_Buzz_Duration");
3131
Wire.begin(); //Join I2C bus
3232

33-
//check if buzzer will acknowledge over I2C
33+
//check if buzzer will connect over I2C
3434
if (buzzer.begin() == false) {
35-
Serial.println("Device did not acknowledge! Freezing.");
35+
Serial.println("Device did not connect! Freezing.");
3636
while (1);
3737
}
38-
Serial.println("Buzzer acknowledged.");
38+
Serial.println("Buzzer connected.");
3939
}
4040

4141
void loop() {

examples/Example_04_Buzz_Volume/Example_04_Buzz_Volume.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ void setup() {
3535
Serial.println("Qwiic Buzzer Example_04_Buzz_Volume");
3636
Wire.begin(); //Join I2C bus
3737

38-
//check if buzzer will acknowledge over I2C
38+
//check if buzzer will connect over I2C
3939
if (buzzer.begin() == false) {
40-
Serial.println("Device did not acknowledge! Freezing.");
40+
Serial.println("Device did not connect! Freezing.");
4141
while (1);
4242
}
43-
Serial.println("Buzzer acknowledged.");
43+
Serial.println("Buzzer connected.");
4444
}
4545

4646
void loop() {

examples/Example_05_ChangeI2CAddress/Example_05_ChangeI2CAddress.ino

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@
1818
#include <SparkFun_Qwiic_Buzzer_Arduino_Library.h>
1919
QwiicBuzzer buzzer;
2020

21+
// The default address is 0x34, change this if your buzzer currently has a different address!
22+
uint8_t initialAddress = kQwiicBuzzerDefaultAddress;
23+
2124
void setup() {
2225
Serial.begin(115200);
2326
Serial.println("Qwiic Buzzer example - I2C Address Change");
2427
Wire.begin(); //Join I2C bus
2528

26-
//check if device will acknowledge over I2C
27-
if (buzzer.begin(0x34) == false) {
28-
Serial.println("Device did not acknowledge! Running scanner.");
29+
//check if device will connect over I2C
30+
if (buzzer.begin(initialAddress) == false) {
31+
Serial.println("Device did not connect! Running scanner.");
2932
}
3033
else{
31-
Serial.println("Device acknowledged!");
34+
Serial.println("Device connected!");
3235

3336
Serial.println();
3437
Serial.println("Enter a new I2C address for the Qwiic Buzzer to use!");
@@ -66,16 +69,16 @@ void setup() {
6669
delay(100); //give the hardware time to do whatever configuration it needs to do
6770

6871
if (buzzer.isConnected()) {
69-
Serial.println("Device will acknowledge on new I2C address!");
72+
Serial.println("Device will connect on new I2C address!");
7073
}
7174

7275
else {
73-
Serial.println("Device will not acknowledge on new I2C address.");
76+
Serial.println("Device will not connect on new I2C address.");
7477
}
7578
}
7679

7780
else {
78-
Serial.println("Address out of range! Try an adress between 0x08 and 0x77");
81+
Serial.println("Address out of range! Try an address between 0x08 and 0x77");
7982
}
8083
}
8184

examples/Example_06_SaveSettings/Example_06_SaveSettings.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ void setup() {
4949
Serial.println("Qwiic Buzzer Example_06_SaveSettings");
5050
Wire.begin(); //Join I2C bus
5151

52-
//check if buzzer will acknowledge over I2C
52+
//check if buzzer will connect over I2C
5353
if (buzzer.begin() == false) {
54-
Serial.println("Device did not acknowledge! Freezing.");
54+
Serial.println("Device did not connect! Freezing.");
5555
while (1);
5656
}
57-
Serial.println("Buzzer acknowledged.");
57+
Serial.println("Buzzer connected.");
5858

5959
Serial.println("Buzzing at 1K, volume 3");
6060

examples/Example_07_Melody/Example_07_Melody.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ void setup() {
5050
Serial.println("Qwiic Buzzer Example_07_Buzz_Melody");
5151
Wire.begin(); //Join I2C bus
5252

53-
//check if buzzer will acknowledge over I2C
53+
//check if buzzer will connect over I2C
5454
if (buzzer.begin() == false) {
55-
Serial.println("Device did not acknowledge! Freezing.");
55+
Serial.println("Device did not connect! Freezing.");
5656
while (1);
5757
}
58-
Serial.println("Buzzer acknowledged.");
58+
Serial.println("Buzzer connected.");
5959

6060
Serial.println("Buzzing Melody now...");
6161
play_melody();

examples/Example_08_Sound_Effects/Example_08_Sound_Effects.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ void setup() {
4343
Wire.begin(); //Join I2C bus
4444
Wire.setClock(400000); // sound effects require changing configuration quickly
4545

46-
//check if buzzer will acknowledge over I2C
46+
//check if buzzer will connect over I2C
4747
if (buzzer.begin() == false) {
48-
Serial.println("Device did not acknowledge! Freezing.");
48+
Serial.println("Device did not connect! Freezing.");
4949
while (1);
5050
}
51-
Serial.println("Buzzer acknowledged.");
51+
Serial.println("Buzzer connected.");
5252

5353
for(int i = 0 ; i <= 9 ; i++)
5454
{
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/******************************************************************************
2+
Example_09_SilentConfiguration
3+
4+
This example shows how to configure the buzzer silently.
5+
6+
It then turns the buzzer on and off using setBuzzerActiveReg() and off().
7+
8+
Much like the classic "blink LED sketch" this will buzz
9+
the buzzer once every second.
10+
11+
By Pete Lewis @ SparkFun Electronics
12+
December 2023
13+
14+
Based on code orginally written by Fischer Moseley @ SparkFun Electronics
15+
Original Creation Date: June 28, 2019
16+
17+
SparkFun code, firmware, and software is released under the MIT License.
18+
Please see LICENSE.md for further details.
19+
20+
Hardware Connections:
21+
Connect QWIIC cable from Arduino to Qwiic Buzzer
22+
23+
Distributed as-is; no warranty is given.
24+
******************************************************************************/
25+
26+
#include <SparkFun_Qwiic_Buzzer_Arduino_Library.h>
27+
QwiicBuzzer buzzer;
28+
29+
void setup() {
30+
Serial.begin(115200);
31+
Serial.println("Qwiic Buzzer Example_09_SilentConfiguration");
32+
Wire.begin(); //Join I2C bus
33+
34+
//check if buzzer will connect over I2C
35+
if (buzzer.begin() == false) {
36+
Serial.println("Device did not connect! Freezing.");
37+
while (1);
38+
}
39+
Serial.println("Buzzer connected.");
40+
41+
// Configure with desired settings
42+
// Note, the buzzer will remain silent here
43+
buzzer.configureBuzzer(1000, 2000, 3);
44+
Serial.println("Buzzer configured (silently).");
45+
46+
delay(1000); // Allow some silence
47+
}
48+
49+
void loop() {
50+
buzzer.setBuzzerActiveReg(); // turn on Buzzer with current settings
51+
52+
delay(1000);
53+
54+
buzzer.off();
55+
56+
delay(1000);
57+
}

src/sfeQwiicBuzzer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ sfeTkError_t sfeQwiicBuzzer::configureBuzzer(const uint16_t toneFrequency, const
6161
uint8_t durationMSB = ((duration & 0xFF00) >> 8 );
6262
uint8_t durationLSB = (duration & 0x00FF);
6363

64-
uint8_t data[5];
6564
size_t dataLength = 5;
65+
uint8_t data[dataLength];
6666

6767
data[0] = toneFrequencyMSB; // kSfeQwiicBuzzerRegToneFrequencyMsb
6868
data[1] = toneFrequencyLSB; // kSfeQwiicBuzzerRegToneFrequencyLsb
@@ -106,7 +106,6 @@ sfeTkError_t sfeQwiicBuzzer::setAddress(const uint8_t &address)
106106
{
107107
if (address < 0x08 || address > 0x77)
108108
{
109-
Serial.println("Address out of legal range");
110109
return kSTkErrFail; //error immediately if the address is out of legal range
111110
}
112111

0 commit comments

Comments
 (0)