Struct arduboy_rust::arduboy_tones_library::ArduboyTones
source · pub struct ArduboyTones {}
Expand description
This is the struct to interact in a save way with the ArduboyTones C++ library.
You will need to uncomment the ArduboyTones in the config.toml file.
Implementations§
source§impl ArduboyTones
impl ArduboyTones
sourcepub const fn new() -> ArduboyTones
pub const fn new() -> ArduboyTones
Get a new instance of ArduboyTones
Example
use arduboy_rust::prelude::*;
#[allow(non_upper_case_globals)]
const sound: ArduboyTones = ArduboyTones::new();
sourcepub fn tone(&self, frequency: u16, duration: u32)
pub fn tone(&self, frequency: u16, duration: u32)
Play a single tone.
- freq The frequency of the tone, in hertz.
- dur The duration to play the tone for, in 1024ths of a
second (very close to milliseconds). A duration of 0, or if not provided,
means play forever, or until
noTone()
is called or a new tone or sequence is started.
sourcepub fn tone2(
&self,
frequency1: u16,
duration1: u32,
frequency2: u16,
duration2: u32
)
pub fn tone2( &self, frequency1: u16, duration1: u32, frequency2: u16, duration2: u32 )
Play two tones in sequence.
- freq1,freq2 The frequency of the tone in hertz.
- dur1,dur2 The duration to play the tone for, in 1024ths of a second (very close to milliseconds).
sourcepub fn tone3(
&self,
frequency1: u16,
duration1: u32,
frequency2: u16,
duration2: u32,
frequency3: u16,
duration3: u32
)
pub fn tone3( &self, frequency1: u16, duration1: u32, frequency2: u16, duration2: u32, frequency3: u16, duration3: u32 )
Play three tones in sequence.
- freq1,freq2,freq3 The frequency of the tone, in hertz.
- dur1,dur2,dur3 The duration to play the tone for, in 1024ths of a second (very close to milliseconds).
sourcepub fn tones(&self, tones: *const u16)
pub fn tones(&self, tones: *const u16)
Play a tone sequence from frequency/duration pairs in a PROGMEM array.
- tones A pointer to an array of frequency/duration pairs.
The array must be placed in code space using PROGMEM
.
See the tone()
function for details on the frequency and duration values.
A frequency of 0 for any tone means silence (a musical rest).
The last element of the array must be TONES_END
or TONES_REPEAT
.
Example:
use arduboy_rust::prelude::*;
#[allow(non_upper_case_globals)]
const sound: ArduboyTones = ArduboyTones::new();
progmem!(
static sound1: [u8; _] = [220, 1000, 0, 250, 440, 500, 880, 2000, TONES_END];
);
sound.tones(get_tones_addr!(sound1));
sourcepub fn no_tone(&self)
pub fn no_tone(&self)
Stop playing the tone or sequence.
If a tone or sequence is playing, it will stop. If nothing is playing, this function will do nothing.
sourcepub fn playing(&self) -> bool
pub fn playing(&self) -> bool
Check if a tone or tone sequence is playing.
- return boolean
true
if playing (even if sound is muted).
sourcepub fn tones_in_ram(&self, tones: *mut u32)
pub fn tones_in_ram(&self, tones: *mut u32)
Play a tone sequence from frequency/duration pairs in an array in RAM.
- tones A pointer to an array of frequency/duration pairs.
The array must be located in RAM.
See the tone()
function for details on the frequency and duration values.
A frequency of 0 for any tone means silence (a musical rest).
The last element of the array must be TONES_END
or TONES_REPEAT
.
Example:
use arduboy_rust::prelude::*;
use tones_pitch::*;
let sound2: [u16; 9] = [220, 1000, 0, 250, 440, 500, 880, 2000, TONES_END];
Using tones()
, with the data in PROGMEM, is normally a better
choice. The only reason to use tonesInRAM() would be if dynamically
altering the contents of the array is required.
sourcepub fn volume_mode(&self, mode: u8)
pub fn volume_mode(&self, mode: u8)
Set the volume to always normal, always high, or tone controlled.
One of the following values should be used:
VOLUME_IN_TONE
The volume of each tone will be specified in the tone itself.VOLUME_ALWAYS_NORMAL
All tones will play at the normal volume level.VOLUME_ALWAYS_HIGH
All tones will play at the high volume level.