Skip to content

Commit 14e3d18

Browse files
committed
Multiple buzzer example
1 parent 387b5d0 commit 14e3d18

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/******************************************************************************
2+
Example_10_Buzz_Multiple
3+
4+
This example shows how to control multiple buzzers.
5+
6+
Note, you must use the ChangeI2CAddress example to change the address of your
7+
second (or third, etc.) buzzers. Here, we are using "0x35" for the address
8+
of buzzer2.
9+
10+
It turns each buzzer on and off with their own unique frequencies in a
11+
unique pattern.
12+
13+
By Pete Lewis @ SparkFun Electronics
14+
February 2024
15+
16+
Based on code originally written by Fischer Moseley @ SparkFun Electronics
17+
Original Creation Date: June 28, 2019
18+
19+
SparkFun code, firmware, and software is released under the MIT License.
20+
Please see LICENSE.md for further details.
21+
22+
Hardware Connections:
23+
Connect QWIIC cable from Arduino to Qwiic Buzzers
24+
25+
Distributed as-is; no warranty is given.
26+
******************************************************************************/
27+
28+
#include <SparkFun_Qwiic_Buzzer_Arduino_Library.h>
29+
QwiicBuzzer buzzer1;
30+
QwiicBuzzer buzzer2; // create a second buzzer
31+
32+
#define BUZZER_1_ADDRESS SFE_QWIIC_BUZZER_DEFAULT_ADDRESS // default is 0x34
33+
#define BUZZER_2_ADDRESS 0x35
34+
35+
void setup() {
36+
Serial.begin(115200);
37+
Serial.println("Qwiic Buzzer Example_10_Buzz_Multiple");
38+
Wire.begin(); //Join I2C bus
39+
40+
//check if buzzer 1 will connect over I2C
41+
if (buzzer1.begin(BUZZER_1_ADDRESS) == false) {
42+
Serial.println("Device 1 did not connect! Freezing.");
43+
while (1);
44+
}
45+
Serial.println("Buzzer 1 connected.");
46+
47+
//check if buzzer 2 will connect over I2C
48+
if (buzzer2.begin(BUZZER_2_ADDRESS) == false) {
49+
Serial.println("Device 2 did not connect! Freezing.");
50+
while (1);
51+
}
52+
Serial.println("Buzzer 2 connected.");
53+
}
54+
55+
void loop() {
56+
buzzer1.configureBuzzer(SFE_QWIIC_BUZZER_NOTE_C4);
57+
buzzer1.on();
58+
59+
delay(1000);
60+
61+
buzzer2.configureBuzzer(SFE_QWIIC_BUZZER_NOTE_E6);
62+
buzzer2.on();
63+
64+
delay(1000);
65+
66+
buzzer1.off();
67+
68+
delay(1000);
69+
70+
buzzer2.off();
71+
72+
delay(1000);
73+
}

0 commit comments

Comments
 (0)