Skip to content

Commit cb6d488

Browse files
committed
ex6 save settings working
1 parent d2b16b8 commit cb6d488

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/******************************************************************************
2+
Example_06_SaveSettings
3+
4+
This example shows how to save settings to the buzzer.
5+
6+
It buzzes the buzzer once, and then commands it to save the settings.
7+
8+
It then does nothing more in the main loop. It is up to you to trigger using
9+
the TRIGGER header pin.
10+
11+
NOTE, TRIGGER PIN does utilize frequency, duration and volume. This means you can
12+
set it up to be a "momentary" trigger button, or a "one-shot" button.
13+
14+
When Duration=0, trigger is "momentary" trigger button.
15+
16+
When Duration>0, trigger will fire a "one-shot" buzz of duration length.
17+
18+
Note, this is most practically used when planning to trigger the buzzer using
19+
only the TRIGGER header pin.
20+
21+
This is useful if you want to set the frequency, duration, volume to your
22+
desired settings, and then have it remember them for next time you power your
23+
Qwiic buzzer up. Then you can use the TRIGGER header to cause the buzzer to
24+
buzz at your saved settings.
25+
26+
Note, the "on()" function accepts three arguments:
27+
on(frequency, duration, volume);
28+
29+
By Pete Lewis @ SparkFun Electronics
30+
December 2023
31+
32+
Based on code originally written by Fischer Moseley @ SparkFun Electronics
33+
Original Creation Date: June 28, 2019
34+
35+
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
36+
local, and you've found our code helpful, please buy us a round!
37+
38+
Hardware Connections:
39+
Connect QWIIC cable from Arduino to Qwiic Buzzer
40+
41+
Distributed as-is; no warranty is given.
42+
******************************************************************************/
43+
44+
#include <SparkFun_Qwiic_Buzzer_Arduino_Library.h>
45+
QwiicBuzzer buzzer;
46+
47+
void setup() {
48+
Serial.begin(115200);
49+
Serial.println("Qwiic Buzzer Example_06_SaveSettings");
50+
Wire.begin(); //Join I2C bus
51+
52+
//check if buzzer will acknowledge over I2C
53+
if (buzzer.begin() == false) {
54+
Serial.println("Device did not acknowledge! Freezing.");
55+
while (1);
56+
}
57+
Serial.println("Buzzer acknowledged.");
58+
59+
Serial.println("Buzzing at 1K, volume 3");
60+
61+
// Comment/Un-Comment the following "buzzer.on()" example lines to try different settings:
62+
63+
// "MOMENTARY" SETUP
64+
buzzer.on(1000, 0, 3); // frequency: 1KHz, duration: 0 (aka forever), volume: 3
65+
66+
// "ONE-SHOT" Setup (aka adding in a duration amount).
67+
// buzzer.on(1000, 100, 3); // frequency: 1KHz, duration: 100ms, volume: 3
68+
69+
delay(1000);
70+
71+
Serial.println("Buzzer OFF");
72+
buzzer.off();
73+
74+
Serial.println("Saving settings now...");
75+
buzzer.saveSettings();
76+
77+
Serial.println("Goodbye.");
78+
}
79+
80+
void loop() {
81+
// nothing here
82+
// use the TRIGGER header pin to cause the buzzer to make sounds
83+
}

src/SparkFun_Qwiic_Buzzer_Arduino_Library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ bool QwiicBuzzer::on(uint16_t toneFrequency, uint16_t duration, uint8_t volume)
142142

143143
bool QwiicBuzzer::off()
144144
{
145-
return BUZZERconfig(0, 0, 0);
145+
return clearBuzzerActiveReg();
146146
}
147147

148148
bool QwiicBuzzer::saveSettings()

0 commit comments

Comments
 (0)