koubou no program dayo.

Dependencies:   WiiClassicController_kai mbed

lancer_speaker/lancer_speaker.cpp

Committer:
kambara1415
Date:
2016-09-08
Revision:
3:14f0a05e4166
Parent:
1:e9020a93ef86

File content as of revision 3:14f0a05e4166:

#include "mbed.h"
#include "lancer_speaker.h"


Speaker::Speaker(PinName pin): _pin(pin){
    _pin = 0;
}

void Speaker::tone(int freq, int duration)
{
    _duration = duration;
    _freq = freq;
    _time.attach_us(this, &Speaker::flip, 500000/_freq);
}

void Speaker::noTone()
{
    _time.detach();
}

void Speaker::flip()
{
    _pin = !_pin;
    if(_duration < _count*500/_freq){
        _count = 0;
        _time.detach();
    }
    _count++;
}