FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
API class for tone generation to a buzzer (or better an amplifier) connected to pin OUTPUT
.
More...
#include <fastarduino/devices/tones.h>
Public Types | |
using | PRESCALER = typename SQWGEN::TIMER::PRESCALER |
The TimerPrescaler type matching the selected NTIMER. More... | |
using | COUNTER = typename SQWGEN::TIMER::TYPE |
The counter type (uint8_t or uint16_t ) for the selected NTIMER. More... | |
Public Member Functions | |
ToneGenerator ()=default | |
Create a new generator of tones. | |
void | start_tone (Tone tone) |
Start generating a tone on the connected buzzer until stop_tone() is called. More... | |
void | start_tone (PRESCALER prescaler, COUNTER counter) |
Start generating a tone on the connected buzzer until stop_tone() is called. More... | |
void | stop_tone () |
Stop the tone being currently generated to the connected buzzer. More... | |
API class for tone generation to a buzzer (or better an amplifier) connected to pin OUTPUT
.
This is a rather low-level API. If you want to play suites of tones ("melodies"), then you should better use devices::audio::TonePlayer
. Most provided methods come in two flavours:
Tone
argument (that will be converted to a note frequency)NTIMER | the AVR timer to use for the underlying Timer |
OUTPUT | the board::PWMPin connected to the buzzer; this must be the pin OCnA, where n is the AVR Timer number |
using devices::audio::ToneGenerator< NTIMER, OUTPUT >::PRESCALER = typename SQWGEN::TIMER::PRESCALER |
using devices::audio::ToneGenerator< NTIMER, OUTPUT >::COUNTER = typename SQWGEN::TIMER::TYPE |
|
inline |
Start generating a tone on the connected buzzer until stop_tone()
is called.
If you would like to generate a tone for a given duration, you should use tone()
instead.
tone | the tone to generate |
|
inline |
Start generating a tone on the connected buzzer until stop_tone()
is called.
If you would like to generate a tone for a given duration, you should use tone()
instead.
prescaler | the timer prescaler value to use to produce the required tone |
counter | the timer counter value to use to produce the required tone |
|
inline |