Josh Davy / Mbed 2 deprecated Flip

Dependencies:   mbed el17jd

Committer:
joshdavy
Date:
Mon May 06 14:43:01 2019 +0000
Revision:
11:db27d3838514
Parent:
8:21b6d4dbce44
Child:
14:1e6f74233e8e
test

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 11:db27d3838514 15
joshdavy 11:db27d3838514 16
joshdavy 5:b9cf407bcc63 17 void Music::init(const int* data,int length)
joshdavy 4:afbf3dd71403 18 {
joshdavy 5:b9cf407bcc63 19
joshdavy 4:afbf3dd71403 20 _data = data;
joshdavy 5:b9cf407bcc63 21 _length = length;
joshdavy 6:2ca1516ec1e2 22 speaker.period(0.00003); // Has to << then 1/sample rate
joshdavy 4:afbf3dd71403 23 speaker.write(0); // until music played stay silent
joshdavy 5:b9cf407bcc63 24 _index = 0;
joshdavy 4:afbf3dd71403 25 }
joshdavy 4:afbf3dd71403 26
joshdavy 5:b9cf407bcc63 27 void Music::play_next()
joshdavy 4:afbf3dd71403 28 {
joshdavy 5:b9cf407bcc63 29 double duty_cycle;
joshdavy 5:b9cf407bcc63 30 duty_cycle = ((128-_data[_index]*1.7)+128)/256.0;
joshdavy 5:b9cf407bcc63 31 //printf("%i = %f\n",_index,duty_cycle);
joshdavy 5:b9cf407bcc63 32
joshdavy 5:b9cf407bcc63 33 if (_index < _length) {
joshdavy 5:b9cf407bcc63 34 speaker.write(duty_cycle);
joshdavy 4:afbf3dd71403 35
joshdavy 5:b9cf407bcc63 36 _index++;
joshdavy 5:b9cf407bcc63 37 } else {
joshdavy 6:2ca1516ec1e2 38 _index = 0;
joshdavy 5:b9cf407bcc63 39 }
joshdavy 4:afbf3dd71403 40
joshdavy 8:21b6d4dbce44 41 }
joshdavy 8:21b6d4dbce44 42
joshdavy 8:21b6d4dbce44 43