Skip to content

Commit ef0ec2f

Browse files
committed
frequency working as MSB and LSB
1 parent 6a7a180 commit ef0ec2f

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

src/SparkFun_Qwiic_Buzzer_Arduino_Library.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,20 @@ uint8_t QwiicBuzzer::getI2Caddress()
105105

106106

107107
/*------------------------ BUZZER Configuration ------------------------ */
108-
bool QwiicBuzzer::BUZZERconfig(uint16_t toneFrequency, uint8_t volume, uint16_t offTime, uint8_t granularity)
108+
bool QwiicBuzzer::BUZZERconfig(uint16_t toneFrequency, uint16_t duration, uint8_t volume)
109109
{
110110
bool success = writeSingleRegister(SFE_QWIIC_BUZZER_VOLUME, volume);
111-
success &= writeDoubleRegister(SFE_QWIIC_BUZZER_TONE_FREQUENCY, toneFrequency);
111+
112+
uint8_t toneFrequencyMSB = ((toneFrequency & 0xFF00) >> 8 );
113+
uint8_t toneFrequencyLSB = (toneFrequency & 0x00FF);
114+
success &= writeSingleRegister(SFE_QWIIC_BUZZER_TONE_FREQUENCY_MSB, toneFrequencyMSB);
115+
success &= writeSingleRegister(SFE_QWIIC_BUZZER_TONE_FREQUENCY_LSB, toneFrequencyLSB);
116+
117+
uint8_t durationMSB = ((duration & 0xFF00) >> 8 );
118+
uint8_t durationLSB = (duration & 0x00FF);
119+
success &= writeSingleRegister(SFE_QWIIC_BUZZER_DURATION_MSB, durationMSB);
120+
success &= writeSingleRegister(SFE_QWIIC_BUZZER_DURATION_LSB, durationLSB);
121+
112122
return success;
113123
}
114124

@@ -122,16 +132,21 @@ bool QwiicBuzzer::LEDon(uint8_t brightness)
122132
return BUZZERconfig(brightness, 0, 0);
123133
}
124134

125-
bool QwiicBuzzer::on(uint16_t toneFrequency, uint8_t volume)
135+
bool QwiicBuzzer::on(uint16_t toneFrequency, uint16_t duration, uint8_t volume)
126136
{
127-
return BUZZERconfig(toneFrequency, volume, 0);
137+
return BUZZERconfig(toneFrequency, duration, volume);
128138
}
129139

130140
bool QwiicBuzzer::off()
131141
{
132142
return BUZZERconfig(0, 0, 0);
133143
}
134144

145+
bool QwiicBuzzer::saveSettings()
146+
{
147+
return writeSingleRegister(SFE_QWIIC_BUZZER_SAVE_SETTINGS, 0x01);
148+
}
149+
135150
/*------------------------- Internal I2C Abstraction ---------------- */
136151

137152
uint8_t QwiicBuzzer::readSingleRegister(Qwiic_Button_Register reg)

src/SparkFun_Qwiic_Buzzer_Arduino_Library.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ class QwiicBuzzer
7575
unsigned long popClickedQueue(); //Returns the oldest value in the queue (milliseconds since first button click), and then removes it.
7676

7777
//LED configuration
78-
bool BUZZERconfig(uint16_t toneFrequency, uint8_t brightness,
79-
uint16_t offTime, uint8_t granularity = 1); //Configures the LED with the given max brightness, granularity (1 is fine for most applications), cycle time, and off time.
78+
bool BUZZERconfig(uint16_t toneFrequency, uint16_t duration,
79+
uint8_t volume); //Configures the LED with the given max brightness, granularity (1 is fine for most applications), cycle time, and off time.
8080
bool LEDoff(); //Turns the onboard LED off
8181
bool LEDon(uint8_t brightness = 255); //Turns the onboard LED on with specified brightness. Set brightness to an integer between 0 and 255, where 0 is off and 255 is max brightness.
82-
bool on(uint16_t toneFrequency = 2730, uint8_t brightness = 255);
82+
bool on(uint16_t toneFrequency = 2730, uint16_t duration = 0, uint8_t volume = 3);
8383
bool off();
84+
bool saveSettings(); // store settings to EEPROM
8485

8586
//Internal I2C Abstraction
8687
uint8_t readSingleRegister(Qwiic_Button_Register reg); //Reads a single 8-bit register.

src/registers.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ enum Qwiic_Button_Register : uint8_t
2626
SFE_QWIIC_BUTTON_ID = 0x00,
2727
SFE_QWIIC_BUTTON_FIRMWARE_MINOR = 0x01,
2828
SFE_QWIIC_BUTTON_FIRMWARE_MAJOR = 0x02,
29-
SFE_QWIIC_BUZZER_TONE_FREQUENCY = 0x03,
29+
SFE_QWIIC_BUZZER_TONE_FREQUENCY_MSB = 0x03,
30+
SFE_QWIIC_BUZZER_TONE_FREQUENCY_LSB = 0x04,
3031
SFE_QWIIC_BUZZER_VOLUME = 0x05,
31-
SFE_QWIIC_BUTTON_I2C_ADDRESS = 0x06,
32+
SFE_QWIIC_BUZZER_DURATION_MSB = 0x06,
33+
SFE_QWIIC_BUZZER_DURATION_LSB = 0x07,
34+
SFE_QWIIC_BUZZER_ACTIVE = 0x08,
35+
SFE_QWIIC_BUZZER_SAVE_SETTINGS = 0x09,
36+
SFE_QWIIC_BUTTON_I2C_ADDRESS = 0x0A,
3237
};
3338

3439
typedef union {

0 commit comments

Comments
 (0)