Skip to content

Commit 51b2e7b

Browse files
committed
more button to buzzer naming stuff
1 parent f386556 commit 51b2e7b

File tree

8 files changed

+87
-177
lines changed

8 files changed

+87
-177
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ UPDATE WHAT DOES THIS LIBRARY DO!?! =)
1414
1515
This library allows the user to:
1616
17-
* Determine whether or not the button/switch is pressed
18-
* Set the brightness of the onboard LED
19-
* Configure the onboard LED's "breathing" effect
20-
* Use button-based interrupts
17+
* Turn the buzzer on and off directly
18+
* Optionally, set the frequency, duration, and volume of the sound
2119
* Adjust the device's I<sup>2</sup>C address
2220
2321
-->

examples/Example5_ChangeI2CAddress/Example5_ChangeI2CAddress.ino

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
2-
A configurator for changing the I2C address on the Qwiic Button/Switch that walks
3-
the user through finding the address of their button, and then changing it!
2+
A configurator for changing the I2C address on the Qwiic Buzzer that walks
3+
the user through finding the address of their buzzer, and then changing it!
44
55
Fischer Moseley @ SparkFun Electronics
66
Original Creation Date: July 30, 2019
@@ -9,30 +9,29 @@
99
local, and you've found our code helpful, please buy us a round!
1010
1111
Hardware Connections:
12-
Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
13-
Plug the button into the shield
14-
Print it to the serial monitor at 115200 baud.
12+
Attach the Qwiic Buzzer to your Redboard via Qwiic Cable
13+
Open and interact with serial monitor at 115200 baud.
1514
1615
Distributed as-is; no warranty is given.
1716
******************************************************************************/
1817

19-
#include <SparkFun_Qwiic_Button.h>
20-
QwiicButton button;
18+
#include <SparkFun_Qwiic_Buzzer_Arduino_Library.h>
19+
QwiicBuzzer buzzer;
2120

2221
void setup() {
2322
Serial.begin(115200);
24-
Serial.println("Qwiic button examples");
23+
Serial.println("Qwiic Buzzer example - I2C Address Change");
2524
Wire.begin(); //Join I2C bus
2625

27-
//check if button will acknowledge over I2C
28-
if (button.begin() == false) {
26+
//check if device will acknowledge over I2C
27+
if (buzzer.begin() == false) {
2928
Serial.println("Device did not acknowledge! Running scanner.");
3029
}
3130
else{
3231
Serial.println("Device acknowledged!");
3332

3433
Serial.println();
35-
Serial.println("Enter a new I2C address for the Qwiic Button/Switch to use!");
34+
Serial.println("Enter a new I2C address for the Qwiic Buzzer to use!");
3635
Serial.println("Don't use the 0x prefix. For instance, if you wanted to");
3736
Serial.println("change the address to 0x5B, you would enter 5B and press enter.");
3837
Serial.println();
@@ -56,7 +55,7 @@ void setup() {
5655
Serial.print("Attempting to set device address to 0x");
5756
Serial.println(newAddress, HEX);
5857

59-
if (button.setI2Caddress(newAddress) == true) {
58+
if (buzzer.setI2Caddress(newAddress) == true) {
6059
Serial.println("Device address set succeeded!");
6160
}
6261

@@ -66,7 +65,7 @@ void setup() {
6665

6766
delay(100); //give the hardware time to do whatever configuration it needs to do
6867

69-
if (button.isConnected()) {
68+
if (buzzer.isConnected()) {
7069
Serial.println("Device will acknowledge on new I2C address!");
7170
}
7271

@@ -89,7 +88,7 @@ void setup() {
8988
}
9089

9190
void loop() {
92-
//if no I2C device found or Qwiic button correctly set to new address,
91+
//if no I2C device found or Qwiic Buzzer correctly set to new address,
9392
//scan for available I2C devices
9493
byte error, address;
9594
int nDevices;

examples/Example_02_Buzz_Frequency/Example_02_Buzz_Frequency.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
By Pete Lewis @ SparkFun Electronics
1111
December 2023
1212
13-
Based on code orginally written by Fischer Moseley @ SparkFun Electronics
13+
Based on code originally written by Fischer Moseley @ SparkFun Electronics
1414
Original Creation Date: June 28, 2019
1515
1616
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
@@ -30,7 +30,7 @@ void setup() {
3030
Serial.println("Qwiic Buzzer Example_02_Buzz_Frequency");
3131
Wire.begin(); //Join I2C bus
3232

33-
//check if button will acknowledge over I2C
33+
//check if buzzer will acknowledge over I2C
3434
if (buzzer.begin() == false) {
3535
Serial.println("Device did not acknowledge! Freezing.");
3636
while (1);

keywords.txt

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
######################################################################
2-
# Syntax Coloring Map for SparkFun Qwiic Button/Switch Arduino Library #
2+
# Syntax Coloring Map for SparkFun Qwiic Buzzer Arduino Library #
33
######################################################################
44
# Class
55
######################################################################
66

7-
QwiicButton KEYWORD1
7+
QwiicBuzzer KEYWORD1
88

99
######################################################################
1010
# Methods and Functions
@@ -18,27 +18,7 @@ getDeviceType KEYWORD2
1818
getFirmwareVersion KEYWORD2
1919
setI2Caddress KEYWORD2
2020
getI2Caddress KEYWORD2
21-
isPressed KEYWORD2
22-
hasBeenClicked KEYWORD2
23-
getDebounceTime KEYWORD2
24-
setDebounceTime KEYWORD2
25-
enablePressedInterrupt KEYWORD2
26-
disablePressedInterrupt KEYWORD2
27-
enableClickedInterrupt KEYWORD2
28-
disableClickedInterrupt KEYWORD2
29-
available KEYWORD2
30-
clearEventBits KEYWORD2
31-
resetInterruptConfig KEYWORD2
32-
isPressedQueueFull KEYWORD2
33-
isPressedQueueEmpty KEYWORD2
34-
timeSinceLastPress KEYWORD2
35-
timeSinceFirstPress KEYWORD2
36-
popPressedQueue KEYWORD2
37-
isClickedQueueFull KEYWORD2
38-
isClickedQueueEmpty KEYWORD2
39-
timeSinceLastClick KEYWORD2
40-
timeSinceFirstClick KEYWORD2
41-
popClickedQueue KEYWORD2
4221
BUZZERconfig KEYWORD2
43-
LEDoff KEYWORD2
44-
LEDon KEYWORD2
22+
off KEYWORD2
23+
on KEYWORD2
24+
saveSettings KEYWORD2

library.properties

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name=SparkFun Qwiic Button and Qwiic Switch Library
2-
version=2.0.6
1+
name=SparkFun Qwiic Buzzer Library
2+
version=0.0.1
33
author=SparkFun Electronics <techsupport@sparkfun.com>
4-
maintainer=Fischer Moseley <fischer.moseley@sparkfun.com>
5-
sentence=Communicates and configures the SparkFun Qwiic Button and Switch.
6-
paragraph=This library allows the user to see the button status, configure the built-in LED, set up interrupts, change I2C addresses, and interface with the onboard button queues.
7-
category=Sensors
8-
url=https://sparkfun.com/products/15584
4+
maintainer=SparkFun Electronics <support@sparkfun.com>
5+
sentence=Communicates and configures the SparkFun Qwiic Buzzer
6+
paragraph=This library allows the user to control the buzzer frequency/duration, and change its I2C addresses.
7+
category=Outputs
8+
url=https://sparkfun.com/products/24474
99
architectures=*

src/SparkFun_Qwiic_Buzzer_Arduino_Library.cpp

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
/******************************************************************************
2-
SparkFun_Qwiic_Button.cpp
3-
SparkFun Qwiic Button/Switch Library Source File
2+
SparkFun_Qwiic_Buzzer_Arduino_Library.cpp
3+
SparkFun Qwiic Buzzer Library Source File
4+
5+
by Pete Lewis @SparkFun Electronics
6+
Jan 2024
7+
8+
Based on original source code written by
49
Fischer Moseley @ SparkFun Electronics
510
Original Creation Date: July 24, 2019
611
7-
This file implements the QwiicButton class, prototyped in SparkFun_Qwiic_Button.h
12+
This file implements the QwiicBuzzer class, prototyped in SparkFun_Qwiic_Buzzer_Arduino_Library.h
813
914
Development environment specifics:
10-
IDE: Arduino 1.8.9
15+
IDE: Arduino 2.2.1
1116
Hardware Platform: Arduino Uno/SparkFun Redboard
12-
Qwiic Button Version: 1.0.0
13-
Qwiic Switch Version: 1.0.0
17+
Qwiic Buzzer Version: v10
1418
1519
This code is Lemonadeware; if you see me (or any other SparkFun employee) at the
1620
local, and you've found our code helpful, please buy us a round!
@@ -48,29 +52,29 @@ bool QwiicBuzzer::isConnected()
4852

4953
uint8_t QwiicBuzzer::deviceID()
5054
{
51-
return readSingleRegister(SFE_QWIIC_BUTTON_ID); //read and return the value in the ID register
55+
return readSingleRegister(SFE_QWIIC_BUZZER_ID); //read and return the value in the ID register
5256
}
5357

5458
bool QwiicBuzzer::checkDeviceID()
5559
{
56-
return (deviceID() == SFE_QWIIC_BUTTON_DEV_ID); //Return true if the device ID matches
60+
return (deviceID() == SFE_QWIIC_BUZZER_DEV_ID); //Return true if the device ID matches
5761
}
5862

5963
uint8_t QwiicBuzzer::getDeviceType()
6064
{
6165
if (isConnected())
6266
{ //only try to get the device ID if the device will acknowledge
6367
uint8_t id = deviceID();
64-
if (id == SFE_QWIIC_BUTTON_DEV_ID)
68+
if (id == SFE_QWIIC_BUZZER_DEV_ID)
6569
return 1;
6670
}
6771
return 0;
6872
}
6973

7074
uint16_t QwiicBuzzer::getFirmwareVersion()
7175
{
72-
uint16_t version = (readSingleRegister(SFE_QWIIC_BUTTON_FIRMWARE_MAJOR)) << 8;
73-
version |= readSingleRegister(SFE_QWIIC_BUTTON_FIRMWARE_MINOR);
76+
uint16_t version = (readSingleRegister(SFE_QWIIC_BUZZER_FIRMWARE_MAJOR)) << 8;
77+
version |= readSingleRegister(SFE_QWIIC_BUZZER_FIRMWARE_MINOR);
7478
return version;
7579
}
7680

@@ -82,7 +86,7 @@ bool QwiicBuzzer::setI2Caddress(uint8_t address)
8286
return 1; //error immediately if the address is out of legal range
8387
}
8488

85-
bool success = writeSingleRegister(SFE_QWIIC_BUTTON_I2C_ADDRESS, address);
89+
bool success = writeSingleRegister(SFE_QWIIC_BUZZER_I2C_ADDRESS, address);
8690

8791
if (success == true)
8892
{
@@ -131,16 +135,6 @@ bool QwiicBuzzer::BUZZERconfig(uint16_t toneFrequency, uint16_t duration, uint8_
131135
return success;
132136
}
133137

134-
bool QwiicBuzzer::LEDoff()
135-
{
136-
return BUZZERconfig(0, 0, 0);
137-
}
138-
139-
bool QwiicBuzzer::LEDon(uint8_t brightness)
140-
{
141-
return BUZZERconfig(brightness, 0, 0);
142-
}
143-
144138
bool QwiicBuzzer::on(uint16_t toneFrequency, uint16_t duration, uint8_t volume)
145139
{
146140
return BUZZERconfig(toneFrequency, duration, volume);
@@ -168,7 +162,7 @@ bool QwiicBuzzer::clearBuzzerActiveReg()
168162

169163
/*------------------------- Internal I2C Abstraction ---------------- */
170164

171-
uint8_t QwiicBuzzer::readSingleRegister(Qwiic_Button_Register reg)
165+
uint8_t QwiicBuzzer::readSingleRegister(Qwiic_Buzzer_Register reg)
172166
{
173167
_i2cPort->beginTransmission(_deviceAddress);
174168
_i2cPort->write(reg);
@@ -183,7 +177,7 @@ uint8_t QwiicBuzzer::readSingleRegister(Qwiic_Button_Register reg)
183177
return 0;
184178
}
185179

186-
uint16_t QwiicBuzzer::readDoubleRegister(Qwiic_Button_Register reg)
180+
uint16_t QwiicBuzzer::readDoubleRegister(Qwiic_Buzzer_Register reg)
187181
{ //little endian
188182
_i2cPort->beginTransmission(_deviceAddress);
189183
_i2cPort->write(reg);
@@ -200,7 +194,7 @@ uint16_t QwiicBuzzer::readDoubleRegister(Qwiic_Button_Register reg)
200194
return 0;
201195
}
202196

203-
unsigned long QwiicBuzzer::readQuadRegister(Qwiic_Button_Register reg)
197+
unsigned long QwiicBuzzer::readQuadRegister(Qwiic_Buzzer_Register reg)
204198
{
205199
_i2cPort->beginTransmission(_deviceAddress);
206200
_i2cPort->write(reg);
@@ -225,7 +219,7 @@ unsigned long QwiicBuzzer::readQuadRegister(Qwiic_Button_Register reg)
225219
return data.integer;
226220
}
227221

228-
bool QwiicBuzzer::writeSingleRegister(Qwiic_Button_Register reg, uint8_t data)
222+
bool QwiicBuzzer::writeSingleRegister(Qwiic_Buzzer_Register reg, uint8_t data)
229223
{
230224
_i2cPort->beginTransmission(_deviceAddress);
231225
_i2cPort->write(reg);
@@ -235,7 +229,7 @@ bool QwiicBuzzer::writeSingleRegister(Qwiic_Button_Register reg, uint8_t data)
235229
return false;
236230
}
237231

238-
bool QwiicBuzzer::writeDoubleRegister(Qwiic_Button_Register reg, uint16_t data)
232+
bool QwiicBuzzer::writeDoubleRegister(Qwiic_Buzzer_Register reg, uint16_t data)
239233
{
240234
_i2cPort->beginTransmission(_deviceAddress);
241235
_i2cPort->write(reg);
@@ -246,7 +240,7 @@ bool QwiicBuzzer::writeDoubleRegister(Qwiic_Button_Register reg, uint16_t data)
246240
return false;
247241
}
248242

249-
uint8_t QwiicBuzzer::writeSingleRegisterWithReadback(Qwiic_Button_Register reg, uint8_t data)
243+
uint8_t QwiicBuzzer::writeSingleRegisterWithReadback(Qwiic_Buzzer_Register reg, uint8_t data)
250244
{
251245
if (writeSingleRegister(reg, data))
252246
return 1;
@@ -255,7 +249,7 @@ uint8_t QwiicBuzzer::writeSingleRegisterWithReadback(Qwiic_Button_Register reg,
255249
return 0;
256250
}
257251

258-
uint16_t QwiicBuzzer::writeDoubleRegisterWithReadback(Qwiic_Button_Register reg, uint16_t data)
252+
uint16_t QwiicBuzzer::writeDoubleRegisterWithReadback(Qwiic_Buzzer_Register reg, uint16_t data)
259253
{
260254
if (writeDoubleRegister(reg, data))
261255
return 1;

0 commit comments

Comments
 (0)