Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3f933d0
toolkit working
lewispg228 Jan 12, 2024
78aa81a
cleanup
lewispg228 Jan 12, 2024
fbef0a3
should be default on this example to start
lewispg228 Jan 12, 2024
ef8e4d0
updating header comments with proper attribution
lewispg228 Jan 15, 2024
8902c4e
naming conventions update
lewispg228 Jan 15, 2024
2641aeb
remove old commented out I2C writes
lewispg228 Jan 15, 2024
80626a8
removed more old commented out I2C writes
lewispg228 Jan 15, 2024
5deeb6a
MIT license in all headers
lewispg228 Jan 16, 2024
55d616e
all "tabs" are now 4 spaces (except in arduino examples)
lewispg228 Jan 16, 2024
0c76127
keywords file lined up
lewispg228 Jan 16, 2024
c6a77ff
moved includes into proper location
lewispg228 Jan 16, 2024
99fe407
class naming updated
lewispg228 Jan 16, 2024
94a8a84
corrected delays and durations in sound effects
lewispg228 Jan 16, 2024
c8e7d3f
removed unnecessary calls to off()
lewispg228 Jan 16, 2024
985a7fe
utilizing writeRegisterRegion()
lewispg228 Jan 17, 2024
27d95f6
removed unnecessary error checking
lewispg228 Jan 17, 2024
a60205f
remove whitespace
lewispg228 Jan 17, 2024
c3ce97f
removing incorrect comments
lewispg228 Jan 17, 2024
514df20
removed sound effect durations
lewispg228 Jan 18, 2024
cd10f72
updates and cleanup
lewispg228 Jan 19, 2024
f88df61
returning errors on sound effects
lewispg228 Jan 19, 2024
008fb4d
update comments for returns on sound effects
lewispg228 Jan 19, 2024
a8f0fc7
sound effects const arguments passed by reference
lewispg228 Jan 19, 2024
6c198b5
namechange to configureBuzzer
lewispg228 Jan 19, 2024
1b8ce22
const arguments for configureBuzzer() and on()
lewispg228 Jan 19, 2024
82390f7
individual sound effect functions private
lewispg228 Jan 19, 2024
5c7721c
renamed class - removed appended "ArdI2C"
lewispg228 Jan 19, 2024
1e46c0c
more description for configureBuzzer()
lewispg228 Jan 19, 2024
eace09c
clarifying units as Hz
lewispg228 Jan 19, 2024
27f8cfc
lots of little stuff + silent config example
lewispg228 Jan 19, 2024
dc776a9
resonant frequency as const
lewispg228 Jan 19, 2024
e8e9983
volume options as macros
lewispg228 Jan 19, 2024
89bb6e8
library version to v1.0.0
lewispg228 Jan 19, 2024
b6e8483
typo
lewispg228 Jan 19, 2024
fd5955f
added missing functions to keywords
lewispg228 Jan 19, 2024
da16715
moving back to all caps and underscore style for some things
lewispg228 Jan 19, 2024
a85cc3b
updating another volume macro
lewispg228 Jan 19, 2024
0f35e32
default err on sound effect switch
lewispg228 Jan 19, 2024
22de055
comment update to tell duration of 0 = forever
lewispg228 Jan 19, 2024
43c6d5b
name change: getAddress to address
lewispg228 Jan 22, 2024
ba4b48e
cost argument in begin
lewispg228 Jan 22, 2024
fbaac5b
Sound effect descriptions
lewispg228 Jan 22, 2024
a62c603
typos and add sound effect descriptions to example header comments
lewispg228 Jan 22, 2024
6d293a4
changed how on() and configureBuzzer() work
lewispg228 Jan 22, 2024
91b4491
device ID
lewispg228 Jan 22, 2024
bd86a3d
Firmware Version read example
lewispg228 Jan 22, 2024
65c2dd9
unnecessary "0x0"
lewispg228 Jan 22, 2024
45244f0
removing call to off() - handled by durations
lewispg228 Jan 23, 2024
e930e26
remove old comment
lewispg228 Jan 23, 2024
50182d2
formatting
lewispg228 Jan 24, 2024
20bbbf7
header and cpp file in the library are generic c++ files
lewispg228 Jan 24, 2024
2c4bff6
spellcheck typos
lewispg228 Jan 24, 2024
842fe2f
formatted correctly with clang set to Microsoft
lewispg228 Jan 24, 2024
298e207
typo
lewispg228 Jan 24, 2024
f6b2980
re-ordering includes to fix compile error
lewispg228 Jan 24, 2024
c8e6826
needed stdint.h to properly compile
lewispg228 Jan 24, 2024
96afb84
typo
lewispg228 Jan 26, 2024
b5141e3
"rest" note is shown as a constant
lewispg228 Jan 26, 2024
3d1b942
no longer passing in arguments by reference
lewispg228 Jan 26, 2024
c2a18ab
typo
lewispg228 Jan 26, 2024
d82df4c
correctly using enum for registers
lewispg228 Jan 26, 2024
5346e81
moved to bool status return for example 8
lewispg228 Jan 26, 2024
a5ee6d8
moved to bool status return for example 9
lewispg228 Jan 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/Example_01_Buzz/Example_01_Buzz.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
By Pete Lewis @ SparkFun Electronics
December 2023

Based on code orginally written by Fischer Moseley @ SparkFun Electronics
Based on code originally written by Fischer Moseley @ SparkFun Electronics
Original Creation Date: June 28, 2019

This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
local, and you've found our code helpful, please buy us a round!
SparkFun code, firmware, and software is released under the MIT License.
Please see LICENSE.md for further details.

Hardware Connections:
Connect QWIIC cable from Arduino to Qwiic Buzzer
Expand All @@ -28,12 +28,12 @@ void setup() {
Serial.println("Qwiic Buzzer Example_01_Buzz");
Wire.begin(); //Join I2C bus

//check if buzzer will acknowledge over I2C
//check if buzzer will connect over I2C
if (buzzer.begin() == false) {
Serial.println("Device did not acknowledge! Freezing.");
Serial.println("Device did not connect! Freezing.");
while (1);
}
Serial.println("Buzzer acknowledged.");
Serial.println("Buzzer connected.");
}

void loop() {
Expand Down
18 changes: 11 additions & 7 deletions examples/Example_02_Buzz_Frequency/Example_02_Buzz_Frequency.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
Based on code originally written by Fischer Moseley @ SparkFun Electronics
Original Creation Date: June 28, 2019

This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
local, and you've found our code helpful, please buy us a round!
SparkFun code, firmware, and software is released under the MIT License.
Please see LICENSE.md for further details.

Hardware Connections:
Connect QWIIC cable from Arduino to Qwiic Buzzer
Expand All @@ -30,22 +30,26 @@ void setup() {
Serial.println("Qwiic Buzzer Example_02_Buzz_Frequency");
Wire.begin(); //Join I2C bus

//check if buzzer will acknowledge over I2C
//check if buzzer will connect over I2C
if (buzzer.begin() == false) {
Serial.println("Device did not acknowledge! Freezing.");
Serial.println("Device did not connect! Freezing.");
while (1);
}
Serial.println("Buzzer acknowledged.");
Serial.println("Buzzer connected.");
}

void loop() {
buzzer.on(2730); // resonant frequency is 2.73KHz
// Configure with desired settings
// Resonant frequency is 2.73KHz
buzzer.configureBuzzer(SFE_QWIIC_BUZZER_RESONANT_FREQUENCY);
buzzer.on();
delay(100);

buzzer.off();
delay(1000);

buzzer.on(1000); // try out 1KHz for fun
buzzer.configureBuzzer(1000); // set frequency to 1KHz
buzzer.on();
delay(100);

buzzer.off();
Expand Down
16 changes: 9 additions & 7 deletions examples/Example_03_Buzz_Duration/Example_03_Buzz_Duration.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
Based on code originally written by Fischer Moseley @ SparkFun Electronics
Original Creation Date: June 28, 2019

This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
local, and you've found our code helpful, please buy us a round!
SparkFun code, firmware, and software is released under the MIT License.
Please see LICENSE.md for further details.

Hardware Connections:
Connect QWIIC cable from Arduino to Qwiic Buzzer
Expand All @@ -30,19 +30,21 @@ void setup() {
Serial.println("Qwiic Buzzer Example_03_Buzz_Duration");
Wire.begin(); //Join I2C bus

//check if buzzer will acknowledge over I2C
//check if buzzer will connect over I2C
if (buzzer.begin() == false) {
Serial.println("Device did not acknowledge! Freezing.");
Serial.println("Device did not connect! Freezing.");
while (1);
}
Serial.println("Buzzer acknowledged.");
Serial.println("Buzzer connected.");
}

void loop() {
buzzer.on(2730, 100); // frequency: 2.73KHz, duration: 100ms
buzzer.configureBuzzer(2730, 100); // frequency: 2.73KHz, duration: 100ms
buzzer.on();
delay(1000);

buzzer.on(1000, 500); // frequency: 1K, duration: 500ms
buzzer.configureBuzzer(1000, 500); // frequency: 1K, duration: 500ms
buzzer.on();
delay(1000);

// Note, we dont' have to call buzzer.off(), because it will automatically turn
Expand Down
34 changes: 19 additions & 15 deletions examples/Example_04_Buzz_Volume/Example_04_Buzz_Volume.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

This example shows how to control the buzzer to sound at different volumes.

Note, the "on()" function accepts three arguments, and you must send all three
Note, the "configureBuzzer()" function accepts three arguments, and you must send all three
in order to access the volume control.

on(frequency, duration, volume);
configureBuzzer(frequency, duration, volume);

It turns the buzzer on and off.
Much like the classic "blink LED sketch" this will buzz
Expand All @@ -18,8 +18,8 @@
Based on code originally written by Fischer Moseley @ SparkFun Electronics
Original Creation Date: June 28, 2019

This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
local, and you've found our code helpful, please buy us a round!
SparkFun code, firmware, and software is released under the MIT License.
Please see LICENSE.md for further details.

Hardware Connections:
Connect QWIIC cable from Arduino to Qwiic Buzzer
Expand All @@ -35,29 +35,33 @@ void setup() {
Serial.println("Qwiic Buzzer Example_04_Buzz_Volume");
Wire.begin(); //Join I2C bus

//check if buzzer will acknowledge over I2C
//check if buzzer will connect over I2C
if (buzzer.begin() == false) {
Serial.println("Device did not acknowledge! Freezing.");
Serial.println("Device did not connect! Freezing.");
while (1);
}
Serial.println("Buzzer acknowledged.");
Serial.println("Buzzer connected.");
}

void loop() {
Serial.println("Volume: Quietest (1)");
buzzer.on(2730, 100, 1); // frequency: 2.73KHz, duration: 100ms, volume: 1
Serial.println("Volume: MIN (1)");
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MIN); // frequency: 2.73KHz, duration: 100ms, volume: MIN
buzzer.on();
delay(1000);

Serial.println("Volume: Mid-low (2)");
buzzer.on(2730, 100, 2); // frequency: 2.73KHz, duration: 100ms, volume: 2
Serial.println("Volume: LOW (2)");
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_LOW); // frequency: 2.73KHz, duration: 100ms, volume: LOW
buzzer.on();
delay(1000);

Serial.println("Volume: Mid-high (3)");
buzzer.on(2730, 100, 3); // frequency: 2.73KHz, duration: 100ms, volume: 3
Serial.println("Volume: MID (3)");
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MID); // frequency: 2.73KHz, duration: 100ms, volume: MID
buzzer.on();
delay(1000);

Serial.println("Volume: Loudest (4)");
buzzer.on(2730, 100, 4); // frequency: 2.73KHz, duration: 100ms, volume: 4
Serial.println("Volume: MAX (4)");
buzzer.configureBuzzer(2730, 100, SFE_QWIIC_BUZZER_VOLUME_MAX); // frequency: 2.73KHz, duration: 100ms, volume: MAX
buzzer.on();
delay(1000);

// Note, we dont' have to use buzzer.off(), because it will automatically turn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Fischer Moseley @ SparkFun Electronics
Original Creation Date: July 30, 2019

This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
local, and you've found our code helpful, please buy us a round!
SparkFun code, firmware, and software is released under the MIT License.
Please see LICENSE.md for further details.

Hardware Connections:
Attach the Qwiic Buzzer to your Redboard via Qwiic Cable
Expand All @@ -18,17 +18,20 @@
#include <SparkFun_Qwiic_Buzzer_Arduino_Library.h>
QwiicBuzzer buzzer;

// The default address is 0x34, change this if your buzzer currently has a different address!
uint8_t initialAddress = SFE_QWIIC_BUZZER_DEFAULT_ADDRESS;

void setup() {
Serial.begin(115200);
Serial.println("Qwiic Buzzer example - I2C Address Change");
Wire.begin(); //Join I2C bus

//check if device will acknowledge over I2C
if (buzzer.begin(0x5B) == false) {
Serial.println("Device did not acknowledge! Running scanner.");
//check if device will connect over I2C
if (buzzer.begin(initialAddress) == false) {
Serial.println("Device did not connect! Running scanner.");
}
else{
Serial.println("Device acknowledged!");
Serial.println("Device connected!");

Serial.println();
Serial.println("Enter a new I2C address for the Qwiic Buzzer to use!");
Expand All @@ -51,11 +54,11 @@ void setup() {

if (success) {
if (newAddress > 0x08 && newAddress < 0x77) {
Serial.println("Character recieved, and device address is valid!");
Serial.println("Character received, and device address is valid!");
Serial.print("Attempting to set device address to 0x");
Serial.println(newAddress, HEX);

if (buzzer.setI2Caddress(newAddress) == true) {
if (buzzer.setAddress(newAddress) == true) {
Serial.println("Device address set succeeded!");
}

Expand All @@ -66,16 +69,16 @@ void setup() {
delay(100); //give the hardware time to do whatever configuration it needs to do

if (buzzer.isConnected()) {
Serial.println("Device will acknowledge on new I2C address!");
Serial.println("Device will connect on new I2C address!");
}

else {
Serial.println("Device will not acknowledge on new I2C address.");
Serial.println("Device will not connect on new I2C address.");
}
}

else {
Serial.println("Address out of range! Try an adress between 0x08 and 0x77");
Serial.println("Address out of range! Try an address between 0x08 and 0x77");
}
}

Expand All @@ -99,7 +102,7 @@ void loop() {
for (address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// the Write.endTransmission to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
Expand Down
19 changes: 10 additions & 9 deletions examples/Example_06_SaveSettings/Example_06_SaveSettings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
Qwiic buzzer up. Then you can use the TRIGGER header to cause the buzzer to
buzz at your saved settings.

Note, the "on()" function accepts three arguments:
on(frequency, duration, volume);
Note, the "configureBuzzer()" function accepts three arguments:
configureBuzzer(frequency, duration, volume);

By Pete Lewis @ SparkFun Electronics
December 2023

Based on code originally written by Fischer Moseley @ SparkFun Electronics
Original Creation Date: June 28, 2019

This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
local, and you've found our code helpful, please buy us a round!
SparkFun code, firmware, and software is released under the MIT License.
Please see LICENSE.md for further details.

Hardware Connections:
Connect QWIIC cable from Arduino to Qwiic Buzzer
Expand All @@ -49,23 +49,24 @@ void setup() {
Serial.println("Qwiic Buzzer Example_06_SaveSettings");
Wire.begin(); //Join I2C bus

//check if buzzer will acknowledge over I2C
//check if buzzer will connect over I2C
if (buzzer.begin() == false) {
Serial.println("Device did not acknowledge! Freezing.");
Serial.println("Device did not connect! Freezing.");
while (1);
}
Serial.println("Buzzer acknowledged.");
Serial.println("Buzzer connected.");

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

// Comment/Un-Comment the following "buzzer.on()" example lines to try different settings:

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

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

buzzer.on();
delay(1000);

Serial.println("Buzzer OFF");
Expand Down
31 changes: 19 additions & 12 deletions examples/Example_07_Melody/Example_07_Melody.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
By Pete Lewis @ SparkFun Electronics
December 2023

Based on original source code written by Tom Igeo in Jan 2010:
https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMelody
http://www.arduino.cc/en/Tutorial/Tone

Based on code originally written by Fischer Moseley @ SparkFun Electronics
Original Creation Date: June 28, 2019

This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
local, and you've found our code helpful, please buy us a round!
SparkFun code, firmware, and software is released under the MIT License.
Please see LICENSE.md for further details.

Hardware Connections:
Connect QWIIC cable from Arduino to Qwiic Buzzer
Expand All @@ -23,28 +27,32 @@ QwiicBuzzer buzzer;

// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
SFE_QWIIC_BUZZER_NOTE_C4,
SFE_QWIIC_BUZZER_NOTE_G3,
SFE_QWIIC_BUZZER_NOTE_G3,
SFE_QWIIC_BUZZER_NOTE_A3,
SFE_QWIIC_BUZZER_NOTE_G3,
SFE_QWIIC_BUZZER_NOTE_REST, // silence (aka "rest")
SFE_QWIIC_BUZZER_NOTE_B3,
SFE_QWIIC_BUZZER_NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};

#define BUZZER_VOLUME 4 // loudest!!
//#define BUZZER_VOLUME 3 // pretty good volume for most things

void setup() {
Serial.begin(115200);
Serial.println("Qwiic Buzzer Example_07_Buzz_Melody");
Wire.begin(); //Join I2C bus

//check if buzzer will acknowledge over I2C
//check if buzzer will connect over I2C
if (buzzer.begin() == false) {
Serial.println("Device did not acknowledge! Freezing.");
Serial.println("Device did not connect! Freezing.");
while (1);
}
Serial.println("Buzzer acknowledged.");
Serial.println("Buzzer connected.");

Serial.println("Buzzing Melody now...");
play_melody();
Expand All @@ -63,13 +71,12 @@ void play_melody()
// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
buzzer.on(melody[thisNote], noteDuration, BUZZER_VOLUME);
buzzer.configureBuzzer(melody[thisNote], noteDuration, SFE_QWIIC_BUZZER_VOLUME_MAX);
buzzer.on();

// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
buzzer.off();
}
}
Loading