2016 catch robo

Dependencies:   mbed WiiClassicController_kai

Committer:
kambara1415
Date:
Mon Jun 24 07:51:58 2019 +0000
Revision:
0:7d81654c5ce8
2016 suiheitakannsetu

Who changed what in which revision?

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