Skip to content

Commit e56e2af

Browse files
committed
Add a new Buzzer.beep() helper method
1 parent c5245d7 commit e56e2af

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

docs/readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ Equivalent to noTone(), it will stop the tone signal
170170
Buzzer.noSound()
171171
```
172172

173+
To emit a beep you can use the `beep()` method:
174+
175+
```
176+
Buzzer.beep();
177+
```
178+
173179
### Relay class
174180

175181
Control both relays and get the status of them

src/Arduino_MKRIoTCarrier_Buzzer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ void MKRIoTCarrier_Buzzer::sound(int freq){
3535
void MKRIoTCarrier_Buzzer::noSound(){
3636
noTone(_pin);
3737
}
38+
39+
void MKRIoTCarrier_Buzzer::beep(int freq, unsigned long duration) {
40+
carrier.Buzzer.sound(freq);
41+
delay(duration);
42+
carrier.Buzzer.noSound();
43+
}

src/Arduino_MKRIoTCarrier_Buzzer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class MKRIoTCarrier_Buzzer{
3131
void sound(int freq);
3232

3333
void noSound();
34+
35+
void beep(int freq = 800, unsigned long duration = 20);
3436

3537
private:
3638
int _pin;

0 commit comments

Comments
 (0)