Skip to content

Commit 1cb1cc7

Browse files
committed
volume working
1 parent a616585 commit 1cb1cc7

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/******************************************************************************
2+
Example_04_Buzz_Volume
3+
4+
This example shows how to control the buzzer to sound at different volumes.
5+
6+
Note, the "on()" function accepts three arguments, and you must send all three
7+
in order to access the volume control.
8+
9+
on(frequency, duration, volume);
10+
11+
It turns the buzzer on and off.
12+
Much like the classic "blink LED sketch" this will buzz
13+
the buzzer once every second at a different volumes.
14+
15+
By Pete Lewis @ SparkFun Electronics
16+
December 2023
17+
18+
Based on code originally written by Fischer Moseley @ SparkFun Electronics
19+
Original Creation Date: June 28, 2019
20+
21+
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
22+
local, and you've found our code helpful, please buy us a round!
23+
24+
Hardware Connections:
25+
Connect QWIIC cable from Arduino to Qwiic Buzzer
26+
27+
Distributed as-is; no warranty is given.
28+
******************************************************************************/
29+
30+
#include <SparkFun_Qwiic_Buzzer_Arduino_Library.h>
31+
QwiicBuzzer buzzer;
32+
33+
void setup() {
34+
Serial.begin(115200);
35+
Serial.println("Qwiic Buzzer Example_04_Buzz_Volume");
36+
Wire.begin(); //Join I2C bus
37+
38+
//check if buzzer will acknowledge over I2C
39+
if (buzzer.begin() == false) {
40+
Serial.println("Device did not acknowledge! Freezing.");
41+
while (1);
42+
}
43+
Serial.println("Buzzer acknowledged.");
44+
}
45+
46+
void loop() {
47+
Serial.println("Volume: Quietest (1)");
48+
buzzer.on(2730, 100, 1); // frequency: 2.73KHz, duration: 100ms, volume: 1
49+
delay(1000);
50+
51+
Serial.println("Volume: Mid-low (2)");
52+
buzzer.on(2730, 100, 2); // frequency: 2.73KHz, duration: 100ms, volume: 2
53+
delay(1000);
54+
55+
Serial.println("Volume: Mid-high (3)");
56+
buzzer.on(2730, 100, 3); // frequency: 2.73KHz, duration: 100ms, volume: 3
57+
delay(1000);
58+
59+
Serial.println("Volume: Loudest (4)");
60+
buzzer.on(2730, 100, 4); // frequency: 2.73KHz, duration: 100ms, volume: 4
61+
delay(1000);
62+
63+
// Note, we dont' have to use buzzer.off(), because it will automatically turn
64+
// off after the duration of each tone is completed.
65+
}

src/SparkFun_Qwiic_Buzzer_Arduino_Library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class QwiicBuzzer
5252
//Buzzer configuration
5353
bool BUZZERconfig(uint16_t toneFrequency, uint16_t duration,
5454
uint8_t volume); //Configures the LED with the given max brightness, granularity (1 is fine for most applications), cycle time, and off time.
55-
bool on(uint16_t toneFrequency = 2730, uint16_t duration = 0, uint8_t volume = 3);
55+
bool on(uint16_t toneFrequency = 2730, uint16_t duration = 0, uint8_t volume = 4);
5656
bool off();
5757
bool saveSettings(); // store settings to EEPROM
5858
bool setBuzzerActiveReg();

0 commit comments

Comments
 (0)