Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed N5110 ShiftReg PinDetect
Music.h
00001 #ifndef MUSIC_H 00002 #define MUSIC_H 00003 00004 /// @file Music.h 00005 00006 #include "mbed.h" 00007 #include "Sprites.h" 00008 // #include "Tone.h" 00009 00010 /// A note is given by its frequency and beat. 00011 struct Note 00012 { 00013 Note(float f, float b = 1.0) : frequency(f), beat(b) {} 00014 float frequency; /// Frequency of note 00015 float beat; /// Normal beat last for 1 cycle 00016 }; 00017 00018 /// Sound uses a piezo buzzer connect to a PWMOut to output sound 00019 class Sound 00020 { 00021 public: 00022 /* Creates a new sound object. 00023 * @param pin The pin of the pwm output the piezo buzzer is connected to. 00024 */ 00025 Sound(PinName buzzerPin); 00026 00027 /// Destructor 00028 ~Sound(); 00029 00030 /// Plays the given note. @param note The note to be played. 00031 void playNote(Note ¬e); 00032 00033 private: 00034 void start() {*buzzer = 0.5;} // Set duty cycle to 50% 00035 void stop() {*buzzer = 0.0;} // Turn off pwm out 00036 00037 // Variables 00038 private: 00039 PwmOut *buzzer; // Piezo buzzer. 00040 Timeout ticker; // Used for stopping sound after the given beat. 00041 }; 00042 00043 /// Sound effects. Commonly used notes. 00044 namespace SFX 00045 { 00046 extern Note PLAYER_DEAD; 00047 extern Note ENEMY_DEAD; 00048 extern Note BULLET_FIRED; 00049 extern Note PLAYER_JUMP; 00050 extern Note RESTART; 00051 } 00052 00053 00054 00055 00056 00057 00058 #endif
Generated on Tue Jul 12 2022 21:30:55 by
