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.
Diff: Music/Music.cpp
- Revision:
- 5:b9cf407bcc63
- Parent:
- 4:afbf3dd71403
- Child:
- 6:2ca1516ec1e2
--- a/Music/Music.cpp Sat Apr 06 11:47:18 2019 +0000
+++ b/Music/Music.cpp Sat Apr 06 14:42:34 2019 +0000
@@ -1,3 +1,7 @@
+
+#include "Music.h"
+PwmOut speaker(PTC10);
+
Music::Music()
{
@@ -8,19 +12,28 @@
}
-Music::init(int * data)
+void Music::init(const int* data,int length)
{
+
_data = data;
- speaker.period(0.000016); // Has to >> then 1/sample rate
+ _length = length;
+ speaker.period(0.00001); // Has to << then 1/sample rate
speaker.write(0); // until music played stay silent
- _index = 0
+ _index = 0;
}
-Music::play_next()
+void Music::play_next()
{
- if (_index < NUM_ELEMENTS) {
- speaker.write(*(_data+index));
- }
+ double duty_cycle;
+ duty_cycle = ((128-_data[_index]*1.7)+128)/256.0;
+ //printf("%i = %f\n",_index,duty_cycle);
+
+ if (_index < _length) {
+ speaker.write(duty_cycle);
+ _index++;
+ } else {
+ printf("%i",_index);
+ }
}
\ No newline at end of file