Josh Davy / Mbed OS Flip_OS_5

Dependencies:   el17jd

Committer:
joshdavy
Date:
Wed Apr 10 11:03:07 2019 +0000
Revision:
6:2ca1516ec1e2
Parent:
5:b9cf407bcc63
Child:
8:21b6d4dbce44
Began implementing "levels" which store the blocks/enemies of each stage

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 6:2ca1516ec1e2 20 speaker.period(0.00003); // 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 6:2ca1516ec1e2 36 _index = 0;
joshdavy 5:b9cf407bcc63 37 }
joshdavy 4:afbf3dd71403 38
joshdavy 4:afbf3dd71403 39 }