Balboa32U4 library
PololuBuzzer.h
Go to the documentation of this file.
1 // Copyright Pololu Corporation. For more information, see http://www.pololu.com/
2 
36 #pragma once
37 
38 #include <avr/pgmspace.h>
39 
42 #define PLAY_AUTOMATIC 0
43 
44 
46 #define PLAY_CHECK 1
47 
48 // n
49 // Equal Tempered Scale is given by f = f * a
50 // n o
51 //
52 // where f is chosen as A above middle C (A4) at f = 440 Hz
53 // o o
54 // and a is given by the twelfth root of 2 (~1.059463094359)
55 
62 #define NOTE_C(x) ( 0 + (x)*12)
63 #define NOTE_C_SHARP(x) ( 1 + (x)*12)
64 #define NOTE_D_FLAT(x) ( 1 + (x)*12)
65 #define NOTE_D(x) ( 2 + (x)*12)
66 #define NOTE_D_SHARP(x) ( 3 + (x)*12)
67 #define NOTE_E_FLAT(x) ( 3 + (x)*12)
68 #define NOTE_E(x) ( 4 + (x)*12)
69 #define NOTE_F(x) ( 5 + (x)*12)
70 #define NOTE_F_SHARP(x) ( 6 + (x)*12)
71 #define NOTE_G_FLAT(x) ( 6 + (x)*12)
72 #define NOTE_G(x) ( 7 + (x)*12)
73 #define NOTE_G_SHARP(x) ( 8 + (x)*12)
74 #define NOTE_A_FLAT(x) ( 8 + (x)*12)
75 #define NOTE_A(x) ( 9 + (x)*12)
76 #define NOTE_A_SHARP(x) (10 + (x)*12)
77 #define NOTE_B_FLAT(x) (10 + (x)*12)
78 #define NOTE_B(x) (11 + (x)*12)
79 
81 #define SILENT_NOTE 0xFF
82 
86 #define DIV_BY_10 (1 << 15)
87 
90 {
91  public:
92 
145  static void playFrequency(unsigned int freq, unsigned int duration,
146  unsigned char volume);
147 
171  static void playNote(unsigned char note, unsigned int duration,
172  unsigned char volume);
173 
264  static void play(const char *sequence);
265 
288  static void playFromProgramSpace(const char *sequence);
289 
310  static void playMode(unsigned char mode);
311 
325  static unsigned char playCheck();
326 
338  static unsigned char isPlaying();
339 
345  static void stopPlaying();
346 
347 
348  private:
349 
350  // initializes timer for buzzer control
351  static void init2();
352  static void init();
353 };
static void playMode(unsigned char mode)
Controls whether play() sequence is played automatically or must be driven with playCheck().
Play beeps and music with the buzzer.
Definition: PololuBuzzer.h:89
static void playNote(unsigned char note, unsigned int duration, unsigned char volume)
Plays the specified note for the specified duration.
static unsigned char playCheck()
Starts the next note in a sequence, if necessary, in PLAY_CHECK mode.
static void playFromProgramSpace(const char *sequence)
Plays the specified sequence of notes from program space.
static unsigned char isPlaying()
Checks whether a note, frequency, or sequence is being played.
static void playFrequency(unsigned int freq, unsigned int duration, unsigned char volume)
Plays the specified frequency for the specified duration.
static void stopPlaying()
Stops any note, frequency, or melody being played.
static void play(const char *sequence)
Plays the specified sequence of notes.