ROCO 104 / MUSIC

Dependents:   ROCO104_7d5m1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pwm_tone.cpp Source File

pwm_tone.cpp

00001 /* Includes ------------------------------------------------------------------*/
00002 #include "pwm_tone.h"
00003 
00004 /* Private typedef -----------------------------------------------------------*/
00005 /* Private define ------------------------------------------------------------*/
00006 /* Private variables ---------------------------------------------------------*/
00007 /* Private function prototypes -----------------------------------------------*/
00008 /* Private functions ---------------------------------------------------------*/
00009 
00010 /**
00011    * @brief     Tune Function
00012    * @param  name : Choose the PwmOut
00013                     period : this param is tune value. (C_3...B_5)
00014                     beat : this param is beat value. (1..16) 1 means 1/16 beat
00015    * @retval    None
00016    */
00017 void Tune(PwmOut name, int period, int beat)
00018 {  
00019     int delay;
00020     
00021     delay = beat*63;
00022     name.period_us(period);
00023     name.write(0.50f); // 50% duty cycle
00024     wait_ms(delay); // 1 beat
00025     //name.period_us(0); // Sound off
00026     name=0;
00027 }
00028 
00029 /**
00030    * @brief     Auto tunes Function
00031    * @param  name : Choose the PwmOut
00032                     period : this param is tune value. (C_3...B_5)
00033                     beat : this param is beat value. (1..16) 1 means 1/16 beat
00034    * @retval    None
00035    */
00036 void Auto_tunes(PwmOut name, int period, int beat)
00037 {    
00038     int delay;
00039     
00040     delay = beat*63;
00041     name.period_us(period);
00042     name.write(0.50f); // 50% duty cycle
00043     wait_ms(delay);
00044 }
00045 
00046 /**
00047    * @brief     Stop tunes Function
00048    * @param  name : Choose the PwmOut
00049    * @retval    None
00050    */
00051 void Stop_tunes(PwmOut name)
00052 {
00053     name.period_us(0);
00054 }