JIAWEI ZHANG / Mbed 2 deprecated ele350ku

Dependencies:   mbed

Dependents:   Exercise8_1-2-3

Fork of ele350 by JIAWEI ZHANG

Revision:
54:aee1b44e62ec
Parent:
53:bbff5bff8b53
Child:
55:2260345179e1
diff -r bbff5bff8b53 -r aee1b44e62ec sine_app.cpp
--- a/sine_app.cpp	Fri Dec 18 14:04:25 2015 +0000
+++ b/sine_app.cpp	Fri Dec 18 16:27:23 2015 +0000
@@ -1,45 +1,47 @@
 #include "sine_app.h"
-
+ 
+ //Constructor. Calls the bass class (App) constructor and creact an AnalogOut object.//
 SineApp::SineApp(Serial* serial) : App("Sine wave", serial) {
+    //Set analogOut attribute to a new AnalogOut object.//
     this->analogOut = new AnalogOut (PA_4);
-    this->amplitude = 2.95f;
-    this->frequence = 50.0f;
+    this->amplitude = 3.0f;                                                          //Set the amplitude value.//
+    this->frequence = 50.0f;                                                          //Set the frequence value.//
 }
 
-void SineApp::start()
-{
-    App::start();
-    this->analogOut->write(this->amplitude/2.95f);
-    this->timer.start(); 
-    if ( this->amplitude > 2.95f ) {
-       this->analogOut->write(0);
-    } else { this->analogOut->write(this->amplitude/2.95f);}
+void SineApp::start()                                                                 //(Overriden) Method that runs when the app starts.//
+{               
+    App::start();                                                                     //Call bass class's start() method.//
+    this->analogOut->write(this->amplitude/3.0f);                                    //Set the output to the amplitude.//
+    this->timer.start();                                                              //Start timer.//
+    if ( this->amplitude > 3.0f ) {                                                  //Define the max amplitude value and check it.//
+       this->analogOut->write(0);                                                     //If >max value, output 0.//
+    } else { this->analogOut->write(this->amplitude/3.0f);}                          //If <max value, out the right expression.//
 
 }
 
-void SineApp::run()
+void SineApp::run()                                                                   //(Overriden) Method that is called repeatedly when the app starts.//
 {
-   this->analogOut->write(this->amplitude+1.0f/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));
+   this->analogOut->write(this->amplitude/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));  //Set the output to the sin expression.// 
    
-   if ( this->frequence > 50.0f ) {
-   this->analogOut->write(0);
-    } else { this->analogOut->write(this->amplitude/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));}
+   if ( this->frequence > 50.0f ) {                                                   //Define the max frequence value and check it.//
+   this->analogOut->write(0);                                                         //If >max value, output 0.//
+    } else { this->analogOut->write(this->amplitude/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));} //If <max value, out the right expression.//
    
 
 }
 
-void SineApp::stop()
+void SineApp::stop()                                                                   //(Overriden) Method that runs when the app stops.//
 {
-    App::stop();
-    this->analogOut->write(0.0f);
-    this->timer.stop();
+    App::stop();                                                                       //Call bass class's stop() method.//
+    this->analogOut->write(0.0f);                                                      //Set output to 0V.//
+    this->timer.stop();                                                                //Stop the time and reset it.//
     this->timer.reset();
 }
-void SineApp::setamplitude(float newamplitude)
+void SineApp::setamplitude(float newamplitude)                                        //(Overriden) Method that could set amplitude.//
 {
-    this->amplitude = newamplitude;
+    this->amplitude = newamplitude;                                                   //Set the new amplitude.//
 }
-void SineApp::setfrequence(float newfrequence)
+void SineApp::setfrequence(float newfrequence)                                        //(Overriden) Method that could set frequence.//
 {
-    this->frequence = newfrequence;
+    this->frequence = newfrequence;                                                   //Set the new frequence.//
 }