Arduboy2 Library  6.0.0
Arduboy2Beep.h
Go to the documentation of this file.
1 
7 #ifndef ARDUBOY2_BEEP_H
8 #define ARDUBOY2_BEEP_H
9 
120 class BeepPin1
121 {
122  public:
123 
146  static uint8_t duration;
147 
156  static void begin();
157 
174  static void tone(uint16_t count);
175 
196  static void tone(uint16_t count, uint8_t dur);
197 
210  static void timer();
211 
221  static void noTone();
222 
250  static constexpr uint16_t freq(const float hz)
251  {
252  return (uint16_t) (((F_CPU / 8 / 2) + (hz / 2)) / hz) - 1;
253  }
254 };
255 
256 
282 class BeepPin2
283 {
284  public:
285 
293  static uint8_t duration;
294 
301  static void begin();
302 
313  static void tone(uint16_t count);
314 
325  static void tone(uint16_t count, uint8_t dur);
326 
333  static void timer();
334 
341  static void noTone();
342 
355  static constexpr uint16_t freq(const float hz)
356  {
357  return (uint16_t) (((F_CPU / 128 / 2) + (hz / 2)) / hz) - 1;
358  }
359 };
360 
361 #endif
362 
BeepPin1
Play simple square wave tones using speaker pin 1.
Definition: Arduboy2Beep.h:121
BeepPin2::noTone
static void noTone()
Stop a tone that is playing on speaker pin 2.
Definition: Arduboy2Beep.cpp:81
BeepPin2::tone
static void tone(uint16_t count)
Play a tone on speaker pin 2 continually, until replaced by a new tone or stopped.
Definition: Arduboy2Beep.cpp:61
BeepPin1::begin
static void begin()
Set up the hardware.
Definition: Arduboy2Beep.cpp:16
BeepPin2::duration
static uint8_t duration
The counter used by the timer() function to time the duration of a tone played on speaker pin 2.
Definition: Arduboy2Beep.h:293
BeepPin1::freq
static constexpr uint16_t freq(const float hz)
Convert a frequency to the required count.
Definition: Arduboy2Beep.h:250
BeepPin2
Play simple square wave tones using speaker pin 2.
Definition: Arduboy2Beep.h:283
BeepPin2::timer
static void timer()
Handle the duration that a tone on speaker pin 2 plays for.
Definition: Arduboy2Beep.cpp:74
BeepPin1::noTone
static void noTone()
Stop a tone that is playing.
Definition: Arduboy2Beep.cpp:41
BeepPin1::duration
static uint8_t duration
The counter used by the timer() function to time the duration of a tone.
Definition: Arduboy2Beep.h:146
BeepPin1::tone
static void tone(uint16_t count)
Play a tone continually, until replaced by a new tone or stopped.
Definition: Arduboy2Beep.cpp:22
BeepPin2::freq
static constexpr uint16_t freq(const float hz)
Convert a frequency to the required count for speaker pin 2.
Definition: Arduboy2Beep.h:355
BeepPin2::begin
static void begin()
Set up the hardware for playing tones using speaker pin 2.
Definition: Arduboy2Beep.cpp:52
BeepPin1::timer
static void timer()
Handle the duration that a tone plays for.
Definition: Arduboy2Beep.cpp:34