Josh Davy / Mbed 2 deprecated Flip

Dependencies:   mbed el17jd

Committer:
joshdavy
Date:
Sat Apr 06 14:42:34 2019 +0000
Revision:
5:b9cf407bcc63
Parent:
4:afbf3dd71403
Child:
6:2ca1516ec1e2
Music player done!. This revision will play successfully play a song.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joshdavy 5:b9cf407bcc63 1
joshdavy 5:b9cf407bcc63 2 #include "Music.h"
joshdavy 5:b9cf407bcc63 3 PwmOut speaker(PTC10);
joshdavy 5:b9cf407bcc63 4
joshdavy 4:afbf3dd71403 5 Music::Music()
joshdavy 4:afbf3dd71403 6 {
joshdavy 4:afbf3dd71403 7
joshdavy 4:afbf3dd71403 8 }
joshdavy 4:afbf3dd71403 9 Music::~Music()
joshdavy 4:afbf3dd71403 10 {
joshdavy 4:afbf3dd71403 11
joshdavy 4:afbf3dd71403 12
joshdavy 4:afbf3dd71403 13
joshdavy 4:afbf3dd71403 14 }
joshdavy 5:b9cf407bcc63 15 void Music::init(const int* data,int length)
joshdavy 4:afbf3dd71403 16 {
joshdavy 5:b9cf407bcc63 17
joshdavy 4:afbf3dd71403 18 _data = data;
joshdavy 5:b9cf407bcc63 19 _length = length;
joshdavy 5:b9cf407bcc63 20 speaker.period(0.00001); // Has to << then 1/sample rate
joshdavy 4:afbf3dd71403 21 speaker.write(0); // until music played stay silent
joshdavy 5:b9cf407bcc63 22 _index = 0;
joshdavy 4:afbf3dd71403 23 }
joshdavy 4:afbf3dd71403 24
joshdavy 5:b9cf407bcc63 25 void Music::play_next()
joshdavy 4:afbf3dd71403 26 {
joshdavy 5:b9cf407bcc63 27 double duty_cycle;
joshdavy 5:b9cf407bcc63 28 duty_cycle = ((128-_data[_index]*1.7)+128)/256.0;
joshdavy 5:b9cf407bcc63 29 //printf("%i = %f\n",_index,duty_cycle);
joshdavy 5:b9cf407bcc63 30
joshdavy 5:b9cf407bcc63 31 if (_index < _length) {
joshdavy 5:b9cf407bcc63 32 speaker.write(duty_cycle);
joshdavy 4:afbf3dd71403 33
joshdavy 5:b9cf407bcc63 34 _index++;
joshdavy 5:b9cf407bcc63 35 } else {
joshdavy 5:b9cf407bcc63 36 printf("%i",_index);
joshdavy 5:b9cf407bcc63 37 }
joshdavy 4:afbf3dd71403 38
joshdavy 4:afbf3dd71403 39 }