Arduboy2 Library
BeepPin2 Class Reference

Play simple square wave tones using speaker pin 2. More...

#include <Arduboy2Beep.h>

+ Collaboration diagram for BeepPin2:

Static Public Member Functions

static void begin ()
 Set up the hardware for playing tones using speaker pin 2. More...
 
static void tone (uint16_t count)
 Play a tone on speaker pin 2 continually, until replaced by a new tone or stopped. More...
 
static void tone (uint16_t count, uint8_t dur)
 Play a tone on speaker pin 2 for a given duration. More...
 
static void timer ()
 Handle the duration that a tone on speaker pin 2 plays for. More...
 
static void noTone ()
 Stop a tone that is playing on speaker pin 2. More...
 
static constexpr uint16_t freq (const float hz)
 Convert a frequency to the required count for speaker pin 2. More...
 

Static Public Attributes

static uint8_t duration = 0
 The counter used by the timer() function to time the duration of a tone played on speaker pin 2. More...
 

Detailed Description

Play simple square wave tones using speaker pin 2.

This class contains the same functions as class BeepPin1 except they use speaker pin 2 instead of speaker pin 1.

Using BeepPin1 is more desirable, as it uses a 16 bit Timer, which can produce a greater frequency range and resolution than the 10 bit Timer used by BeepPin2. However, if the sketch also includes other sound generating code that uses speaker pin 1, BeepPin2 can be used to avoid conflict.

Tone frequencies on speaker pin 2 can range from 61.04Hz to 15625Hz using allowed counts from 3 to 1023.

The formulas for frequency/count conversion are:

count=(62500/frequency)-1
frequency=62500/(count+1)

See the documentation for BeepPin1 for more details.

See also
BeepPin1

Definition at line 282 of file Arduboy2Beep.h.

Member Function Documentation

void BeepPin2::begin ( )
static

Set up the hardware for playing tones using speaker pin 2.

For details see BeepPin1::begin().

Definition at line 52 of file Arduboy2Beep.cpp.

static constexpr uint16_t BeepPin2::freq ( const float  hz)
inlinestatic

Convert a frequency to the required count for speaker pin 2.

Parameters
hzThe frequency, in hertz (cycles per second), to be converted to a count.
Returns
The required count to be loaded into the timer/counter for the given frequency.

For details see BeepPin1::freq().

Definition at line 355 of file Arduboy2Beep.h.

void BeepPin2::noTone ( )
static

Stop a tone that is playing on speaker pin 2.

For details see BeepPin1::noTone().

Definition at line 81 of file Arduboy2Beep.cpp.

void BeepPin2::timer ( )
static

Handle the duration that a tone on speaker pin 2 plays for.

For details see BeepPin1::timer().

Definition at line 74 of file Arduboy2Beep.cpp.

void BeepPin2::tone ( uint16_t  count)
static

Play a tone on speaker pin 2 continually, until replaced by a new tone or stopped.

Parameters
countThe count to be loaded into the timer/counter to play the desired frequency.

For details see BeepPin1::tone(uint16_t).

Definition at line 61 of file Arduboy2Beep.cpp.

void BeepPin2::tone ( uint16_t  count,
uint8_t  dur 
)
static

Play a tone on speaker pin 2 for a given duration.

Parameters
countThe count to be loaded into the timer/counter to play the desired frequency.
durThe duration of the tone, used by timer().

For details see BeepPin1::tone(uint16_t, uint8_t).

Definition at line 66 of file Arduboy2Beep.cpp.

Member Data Documentation

uint8_t BeepPin2::duration = 0
static

The counter used by the timer() function to time the duration of a tone played on speaker pin 2.

For details see BeepPin1::duration.

Definition at line 293 of file Arduboy2Beep.h.


The documentation for this class was generated from the following files: