koubou no program dayo.

Dependencies:   WiiClassicController_kai mbed

Committer:
kambara1415
Date:
Fri Sep 02 00:28:49 2016 +0000
Revision:
1:e9020a93ef86
nhk mae;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kambara1415 1:e9020a93ef86 1 #include "mbed.h"
kambara1415 1:e9020a93ef86 2 #include "lancer_speaker.h"
kambara1415 1:e9020a93ef86 3
kambara1415 1:e9020a93ef86 4
kambara1415 1:e9020a93ef86 5 Speaker::Speaker(PinName pin): _pin(pin){
kambara1415 1:e9020a93ef86 6 _pin = 0;
kambara1415 1:e9020a93ef86 7 }
kambara1415 1:e9020a93ef86 8
kambara1415 1:e9020a93ef86 9 void Speaker::tone(int freq, int duration)
kambara1415 1:e9020a93ef86 10 {
kambara1415 1:e9020a93ef86 11 _duration = duration;
kambara1415 1:e9020a93ef86 12 _freq = freq;
kambara1415 1:e9020a93ef86 13 _time.attach_us(this, &Speaker::flip, 500000/_freq);
kambara1415 1:e9020a93ef86 14 }
kambara1415 1:e9020a93ef86 15
kambara1415 1:e9020a93ef86 16 void Speaker::noTone()
kambara1415 1:e9020a93ef86 17 {
kambara1415 1:e9020a93ef86 18 _time.detach();
kambara1415 1:e9020a93ef86 19 }
kambara1415 1:e9020a93ef86 20
kambara1415 1:e9020a93ef86 21 void Speaker::flip()
kambara1415 1:e9020a93ef86 22 {
kambara1415 1:e9020a93ef86 23 _pin = !_pin;
kambara1415 1:e9020a93ef86 24 if(_duration < _count*500/_freq){
kambara1415 1:e9020a93ef86 25 _count = 0;
kambara1415 1:e9020a93ef86 26 _time.detach();
kambara1415 1:e9020a93ef86 27 }
kambara1415 1:e9020a93ef86 28 _count++;
kambara1415 1:e9020a93ef86 29 }