Music Engine plays Music Macro Language compositions in the background

Dependents:   RETRO_BallsAndPaddle RETRO_BallAndHoles MusicBoxForFathersDay USBSec_mbed-os_dev

Music Engine is a simply library to execute Music Macro Language sequences asynchronously. Learn more about MML on wikipedia http://en.wikipedia.org/wiki/Music_Macro_Language

The following sample plays a simple tune

#include "mbed.h"
#include "MusicEngine.h"

// Play music on MCU Pin 0.18
// The pin should support PWM
MusicEngine music(P0_18);

main()
{
    music.play("T224L8O5CL16>C<P16GP16L8EL16P16>C<GP16L8E.L16P16L8C#L16>C#<P16G#P16L8FL16P16>C#<G#P16L8F.L16P16L8CL16>C<P16GP16L8EL16P16>C<GP16L8E.L16P16D#EFP16FF#GP16GG#AP16L8>C<P8L4>C");
    
    while(1)
    {
    }
}

Files at this revision

API Documentation at this revision

Comitter:
taylorza
Date:
Fri Feb 06 01:37:07 2015 +0000
Parent:
1:7eb27d971c01
Commit message:
Implemented suggestion by maxint to improve the silencing of the PWM signal.

Changed in this revision

MusicEngine.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7eb27d971c01 -r 4f7c4255997a MusicEngine.cpp
--- a/MusicEngine.cpp	Thu Feb 05 04:51:11 2015 +0000
+++ b/MusicEngine.cpp	Fri Feb 06 01:37:07 2015 +0000
@@ -31,8 +31,8 @@
     _pwm(pin),
     _isPlaying(false)
 {
-    _pwm = 0.0f;  
-    _pwm.period(0);
+    _pwm.period_ms(1);
+    _pwm.write(0.0);
 }
 
 void MusicEngine::play(char *mml)
@@ -112,8 +112,8 @@
             
             if (!_isPlaying)
             {
-                _pwm = 0.0;
-                _pwm.period(0);
+                _pwm.period_ms(1);
+                _pwm.write(0.0);
                 _completionCallback.call();
                 return;
             }