tone function Library

Revision:
0:313dfeed320a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pwm_tone.cpp	Fri Jul 24 04:50:30 2015 +0000
@@ -0,0 +1,64 @@
+/**
+ ******************************************************************************
+ * @project  Web Piano 
+ * @author  Justin Kim
+ * @version V1.0.0
+ * @date    03-JUL-2015
+ * @brief   Main program body
+*******************************************************************************
+**/
+/* Includes ------------------------------------------------------------------*/
+#include "pwm_tone.h"
+
+/* Private typedef -----------------------------------------------------------*/
+/* Private define ------------------------------------------------------------*/
+/* Private variables ---------------------------------------------------------*/
+int stop_flag;          //Auto tunes stop flag
+
+/* Private function prototypes -----------------------------------------------*/
+/* Private functions ---------------------------------------------------------*/
+
+/**
+   * @brief     Tune Function
+   * @param  name : Choose the PwmOut
+                    period : this param is tune value. (C_3...B_5)
+   * @retval    None
+   */
+void Tune(PwmOut name, int period)
+{
+    name.period_us(period);
+    name.write(0.50f); // 50% duty cycle
+    wait(1); // 1 beat
+    name.period_us(0); // Sound off
+}
+
+/**
+   * @brief     Auto tunes Function
+   * @param  name : Choose the PwmOut
+                    period : this param is tune value. (C_3...B_5)
+                    beat : this param is beat value. (1..16) 1 means 1/16 beat
+   * @retval    None
+   */
+void Auto_tunes(PwmOut name, int period, int beat)
+{    
+    int delay;
+    
+    if(stop_flag)
+    {
+        Stop_tunes(name);
+    }
+    delay = beat*63;
+    name.period_us(period);
+    name.write(0.50f); // 50% duty cycle
+    wait_ms(delay);
+}
+
+/**
+   * @brief     Stop tunes Function
+   * @param  name : Choose the PwmOut
+   * @retval    None
+   */
+void Stop_tunes(PwmOut name)
+{
+    name.period_us(0);
+}