Files

107 lines
1.3 KiB
Markdown
Raw Permalink Normal View History

2018-12-25 16:04:58 +08:00
# Speaker
2019-05-06 22:54:01 +09:00
## begin()
**Description:**
Initialize the speaker.
**Syntax:**
2020-11-05 11:39:06 +08:00
`begin();`
2019-05-06 22:54:01 +09:00
**Function argument:**
None
**Function return value:**
None
## end()
**Description:**
Mute the speakers and stop the output.
**Syntax:**
2020-11-05 11:39:06 +08:00
`end();`
2019-05-06 22:54:01 +09:00
**Function argument:**
None
**Function return value:**
None
## tone()
2018-12-25 16:04:58 +08:00
2019-02-28 15:56:00 +08:00
**Syntax:**
2018-12-25 16:04:58 +08:00
2020-11-05 11:39:06 +08:00
`tone(uint16_t freq, [uint32_t duration]);`
2019-02-22 16:52:45 +08:00
2019-02-28 15:56:00 +08:00
**Description: Set the pitch of speaker.**
2019-02-22 16:52:45 +08:00
2019-02-28 15:56:00 +08:00
| Param | Description | type |
2019-05-06 22:58:59 +09:00
| --- | --- | --- |
2019-02-28 15:56:00 +08:00
| freq | frequency | uint16_t |
| duration | duration (unit: millisecond) | uint16_t |
2018-12-25 16:04:58 +08:00
**Example**
2021-02-26 17:27:20 +08:00
```clike
2019-02-22 16:52:45 +08:00
#include <M5Stack.h>
2019-02-28 15:56:00 +08:00
void setup() {
M5.begin();
M5.Speaker.tone(900, 1000);
}
2019-05-06 22:54:01 +09:00
```
## setBeep()
**Description:**
Set the beep sound.
**Syntax:**
2020-11-05 11:39:06 +08:00
`setBeep(uint16_t freq, uint16_t duration);`
2019-05-06 22:54:01 +09:00
| Argument | Description | Type |
2019-05-06 22:58:59 +09:00
| --- | --- | --- |
2019-05-06 22:54:01 +09:00
| freq | pitch (frequency Hz) | uint16_t |
| duration | beep time (ms), optional. | uint16_t |
**Example of use:**
2021-02-26 17:27:20 +08:00
```clike
2019-05-06 22:54:01 +09:00
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Speaker.setBeep(900, 1000);
}
```
2019-08-15 19:29:40 +08:00
## mute()
**Description:**
Mute the sound .
**Syntax:**
2020-11-05 11:39:06 +08:00
`void mute(void);`
2019-08-15 19:29:40 +08:00
**Example of use:**
2021-02-26 17:27:20 +08:00
```clike
2019-08-15 19:29:40 +08:00
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Speaker.mute();
}
```