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.
Beeper.cpp
00001 #include "Beeper.h" 00002 #include "mbed.h" 00003 00004 using namespace mbed; 00005 00006 Beeper::Beeper(PinName pin) 00007 : _pwm(pin){} 00008 00009 00010 void Beeper::beep(float freq, float time){ 00011 00012 _pwm.period(1.0/freq); 00013 _pwm.write(0.5); 00014 //wait(time); 00015 //_pwm.write(0.0); 00016 } 00017 void Beeper::stop() { 00018 _pwm.write(0.0); 00019 } 00020 00021 00022 00023 const float MIDINote[128] = { 00024 8.175798916,8.661957218,9.177023997,9.722718241,10.30086115,10.91338223,11.56232571,12.24985737,12.9782718,13.75,14.56761755,15.43385316, 00025 16.35159783,17.32391444,18.35404799,19.44543648,20.60172231,21.82676446,23.12465142,24.49971475,25.9565436,27.5,29.13523509,30.86770633, 00026 32.70319566,34.64782887,36.70809599,38.89087297,41.20344461,43.65352893,46.24930284,48.9994295,51.9130872,55.0,58.27047019,61.73541266, 00027 65.40639133,69.29565774,73.41619198,77.78174593,82.40688923,87.30705786,92.49860568,97.998859,103.8261744,110.0,116.5409404,123.4708253, 00028 130.8127827,138.5913155,146.832384,155.5634919,164.8137785,174.6141157,184.9972114,195.997718,207.6523488,220.0,233.0818808,246.9416506, 00029 261.6255653,277.182631,293.6647679,311.1269837,329.6275569,349.2282314,369.9944227,391.995436,415.3046976,440.0,466.1637615,493.8833013, 00030 523.2511306,554.365262,587.3295358,622.2539674,659.2551138,698.4564629,739.9888454,783.990872,830.6093952,880.0,932.327523,987.7666025, 00031 1046.502261,1108.730524,1174.659072,1244.507935,1318.510228,1396.912926,1479.977691,1567.981744,1661.21879,1760.0,1864.655046,1975.533205, 00032 2093.004522,2217.461048,2349.318143,2489.01587,2637.020455,2793.825851,2959.955382,3135.963488,3322.437581,3520.0,3729.310092,3951.06641, 00033 4186.009045,4434.922096,4698.636287,4978.03174,5274.040911,5587.651703,5919.910763,6271.926976,6644.875161,7040.0,7458.620235,7902.132835, 00034 8372.01809,8869.844191,9397.272573,9956.063479,10548.08182,11175.30341,11839.82153,12543.85395 00035 }; 00036 00037 void Beeper::note(int note, float time){ 00038 00039 if ((note > -1) && (note <128)){ 00040 _pwm.period(1.0/MIDINote[note]); 00041 _pwm.write(0.5); 00042 wait(time); 00043 _pwm.write(0.0);} 00044 00045 }
Generated on Fri Aug 12 2022 04:35:10 by
1.7.2