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.
Dependents: SuperMbedBall Tono
Music.h
00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * 00002 * This is a simple music library for the mbed. * 00003 * * 00004 * Created by: Michael Dushkoff (mad1841@rit.edu) * 00005 * * * * * * * * * * * * * * * * * * * * * * * * * * */ 00006 00007 #ifndef MBED_MUSIC_H 00008 #define MBED_MUSIC_H 00009 00010 #include "mbed.h" 00011 #include "Notes.h" 00012 00013 /* Define the music_note structure */ 00014 typedef struct { 00015 double freq; //The frequency of the note 00016 int duration; //The duration is given by a number [1 - 64] 00017 } music_note; 00018 00019 /* Define an m_song structure */ 00020 typedef struct { 00021 music_note* note; //The notes of the song 00022 int len; //The length of the song 00023 } m_song; 00024 00025 class music { 00026 public: 00027 00028 music(PinName M0); //basic music constructor 00029 music(PinName M0, double freq); //music constructor 00030 void freq(double freq); //Frequency setter 00031 void play(char* song, double tempo, int num); 00032 00033 private: 00034 00035 /* Private functions */ 00036 void flip(); //Flips the output of a pin at a fixed frequency 00037 m_song parse(char* song, int num_notes); //Parses a character array into notes 00038 void init_song(m_song *m, int num); //Initialize an m_song 00039 void dal_song(m_song *m); //Deallocate an m_song 00040 00041 /* Private variables */ 00042 Ticker _flipper; 00043 DigitalOut _M0; 00044 double _freq; 00045 00046 }; 00047 00048 #endif
Generated on Tue Jul 12 2022 18:38:04 by
1.7.2