https://github.com/pilotak/beeper
Mbed library for simplification of toggling the output pin in time pattern.
https://github.com/pilotak/beeper
led mbed-os morse-code pattern piezo toggle
Last synced: 12 months ago
JSON representation
Mbed library for simplification of toggling the output pin in time pattern.
- Host: GitHub
- URL: https://github.com/pilotak/beeper
- Owner: pilotak
- License: mit
- Created: 2020-07-30T11:59:49.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-09T15:57:09.000Z (over 3 years ago)
- Last Synced: 2025-06-02T03:45:55.386Z (about 1 year ago)
- Topics: led, mbed-os, morse-code, pattern, piezo, toggle
- Language: C++
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Beeper
[](https://os.mbed.com/)
Mbed library for simplification of toggling the output pin in time pattern ie.: buzzer/LED or it can be used as morse code generator
You can choose built-in tone duration or you can specify your own. All time units are in millisecods with **bit gain 16**. That means if you want to turn on the output for 16ms you would write it as 1 (32ms = 2, 64ms = 3, etc.), this technique saves the RAM because the "pattern" will be stored in 8-bit array - this has of course a limitation of maximum tone length to 4080ms.
> Please note: `Pause` is reserved "tone duration" in which no tone is played therefore the other tones can't have this duration. You can change this constant through `mbed_app.json` please see bellow.
## Example
```cpp
#include "mbed.h"
#include "Beeper.h"
Beeper beeper(PB_6);
const uint8_t oneshot[] = {Beeper::Short, Beeper::Pause, Beeper::Short};
const uint8_t pattern[] = {Beeper::Long, Beeper::Short, Beeper::Pause, Beeper::Short};
int main() {
// this pattern will be played only once
beeper.pattern(oneshot, sizeof(oneshot));
// give a time to play because previous cmd is asynchronous
ThisThread::sleep_for(5s);
// this pattern will be played in loop until you stop it
beeper.pattern(pattern, sizeof(pattern), true);
ThisThread::sleep_for(20s);
// stop the pattern
beeper = 0;
return 0;
}
```
## How to change `Pause` duration
Remember that the value will be multiplied by 16 as a result.
Total "silence" time: (50 * 16) + (2 * 160ms) *(delay between tones)* = 1120ms
`mbed_app.json`
```json
{
"target_overrides": {
"*": {
"beeper.pause": 50
}
}
}
```