/** @see https:developer.mbed.org/users/justinkim/code/PiezoBuzzer_HelloWorld_WIZwiki-W7500 */
Fork of PWM_Tone_Library by
pwm_tone.cpp@0:d06af372d384, 2015-07-24 (annotated)
- Committer:
- justinkim
- Date:
- Fri Jul 24 05:01:45 2015 +0000
- Revision:
- 0:d06af372d384
bug fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
justinkim | 0:d06af372d384 | 1 | /* Includes ------------------------------------------------------------------*/ |
justinkim | 0:d06af372d384 | 2 | #include "pwm_tone.h" |
justinkim | 0:d06af372d384 | 3 | |
justinkim | 0:d06af372d384 | 4 | /* Private typedef -----------------------------------------------------------*/ |
justinkim | 0:d06af372d384 | 5 | /* Private define ------------------------------------------------------------*/ |
justinkim | 0:d06af372d384 | 6 | /* Private variables ---------------------------------------------------------*/ |
justinkim | 0:d06af372d384 | 7 | /* Private function prototypes -----------------------------------------------*/ |
justinkim | 0:d06af372d384 | 8 | /* Private functions ---------------------------------------------------------*/ |
justinkim | 0:d06af372d384 | 9 | |
justinkim | 0:d06af372d384 | 10 | /** |
justinkim | 0:d06af372d384 | 11 | * @brief Tune Function |
justinkim | 0:d06af372d384 | 12 | * @param name : Choose the PwmOut |
justinkim | 0:d06af372d384 | 13 | period : this param is tune value. (C_3...B_5) |
justinkim | 0:d06af372d384 | 14 | beat : this param is beat value. (1..16) 1 means 1/16 beat |
justinkim | 0:d06af372d384 | 15 | * @retval None |
justinkim | 0:d06af372d384 | 16 | */ |
justinkim | 0:d06af372d384 | 17 | void Tune(PwmOut name, int period, int beat) |
justinkim | 0:d06af372d384 | 18 | { |
justinkim | 0:d06af372d384 | 19 | int delay; |
justinkim | 0:d06af372d384 | 20 | |
justinkim | 0:d06af372d384 | 21 | delay = beat*63; |
justinkim | 0:d06af372d384 | 22 | name.period_us(period); |
justinkim | 0:d06af372d384 | 23 | name.write(0.50f); // 50% duty cycle |
justinkim | 0:d06af372d384 | 24 | wait_ms(delay); // 1 beat |
justinkim | 0:d06af372d384 | 25 | name.period_us(0); // Sound off |
justinkim | 0:d06af372d384 | 26 | } |
justinkim | 0:d06af372d384 | 27 | |
justinkim | 0:d06af372d384 | 28 | /** |
justinkim | 0:d06af372d384 | 29 | * @brief Auto tunes Function |
justinkim | 0:d06af372d384 | 30 | * @param name : Choose the PwmOut |
justinkim | 0:d06af372d384 | 31 | period : this param is tune value. (C_3...B_5) |
justinkim | 0:d06af372d384 | 32 | beat : this param is beat value. (1..16) 1 means 1/16 beat |
justinkim | 0:d06af372d384 | 33 | * @retval None |
justinkim | 0:d06af372d384 | 34 | */ |
justinkim | 0:d06af372d384 | 35 | void Auto_tunes(PwmOut name, int period, int beat) |
justinkim | 0:d06af372d384 | 36 | { |
justinkim | 0:d06af372d384 | 37 | int delay; |
justinkim | 0:d06af372d384 | 38 | |
justinkim | 0:d06af372d384 | 39 | delay = beat*63; |
justinkim | 0:d06af372d384 | 40 | name.period_us(period); |
justinkim | 0:d06af372d384 | 41 | name.write(0.50f); // 50% duty cycle |
justinkim | 0:d06af372d384 | 42 | wait_ms(delay); |
justinkim | 0:d06af372d384 | 43 | } |
justinkim | 0:d06af372d384 | 44 | |
justinkim | 0:d06af372d384 | 45 | /** |
justinkim | 0:d06af372d384 | 46 | * @brief Stop tunes Function |
justinkim | 0:d06af372d384 | 47 | * @param name : Choose the PwmOut |
justinkim | 0:d06af372d384 | 48 | * @retval None |
justinkim | 0:d06af372d384 | 49 | */ |
justinkim | 0:d06af372d384 | 50 | void Stop_tunes(PwmOut name) |
justinkim | 0:d06af372d384 | 51 | { |
justinkim | 0:d06af372d384 | 52 | name.period_us(0); |
justinkim | 0:d06af372d384 | 53 | } |