Skip to content

Commit 497fa01

Browse files
authored
Merge pull request #38 from arduino-libraries/beep
Add a new Buzzer.beep() helper method
2 parents 08cac59 + 901e14d commit 497fa01

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
@@ -164,6 +164,12 @@ Equivalent to noTone(), it will stop the tone signal
164164
Buzzer.noSound()
165165
```
166166

167+
To emit a beep you can use the `beep()` method:
168+
169+
```
170+
Buzzer.beep();
171+
```
172+
167173
### Relay class
168174

169175
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+
this->sound(freq);
41+
delay(duration);
42+
this->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)