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.
Music/Music.cpp
- Committer:
- joshdavy
- Date:
- 2019-04-06
- Revision:
- 5:b9cf407bcc63
- Parent:
- 4:afbf3dd71403
- Child:
- 6:2ca1516ec1e2
File content as of revision 5:b9cf407bcc63:
#include "Music.h"
PwmOut speaker(PTC10);
Music::Music()
{
}
Music::~Music()
{
    
    
}
void Music::init(const int* data,int length)
{
    
    _data = data;
    _length = length;
    speaker.period(0.00001); // Has to << then 1/sample rate
    speaker.write(0); // until music played stay silent
    _index = 0;
}
void Music::play_next()
{
    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);    
    }
        
}