JIAWEI ZHANG / Mbed 2 deprecated ele350ku

Dependencies:   mbed

Dependents:   Exercise8_1-2-3

Fork of ele350 by JIAWEI ZHANG

Revision:
54:aee1b44e62ec
Parent:
50:daa64b483569
--- a/square_app.cpp	Fri Dec 18 14:04:25 2015 +0000
+++ b/square_app.cpp	Fri Dec 18 16:27:23 2015 +0000
@@ -1,47 +1,49 @@
 #include "square_app.h"
 
+//Constructor. Calls the bass class (App) constructor and creact an AnalogOut object.//
 SquareApp::SquareApp(Serial* serial) : App("Square 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 SquareApp::start()
+void SquareApp::start()                                                                           //(Overriden) Method that runs when the app starts.//
 {
-    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);}
+    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 SquareApp::run()
+void SquareApp::run()                                                                             //(Overriden) Method that is called repeatedly when the app starts.//
 {
-   float p;
-   p = (this->frequence*timer.read())-floor(this->frequence*timer.read());
-   if ( p < 0.5f ) {
-       this->analogOut->write(0);
-    } else { this->analogOut->write(this->amplitude/2.95f);} 
+   float p;                                                                                       //Define the float p.//
+   p = (this->frequence*timer.read())-floor(this->frequence*timer.read());                        //p expression.//
+   if ( p < 0.5f ) {                                                                              //Define the mini p value and check it.//
+       this->analogOut->write(0);                                                                 //If < mini value, output 0.//
+    } else { this->analogOut->write(this->amplitude/3.0f);}                                      //Set the output to the sin expression.//
     
-    if ( this->frequence > 50.0f ) {
-       this->analogOut->write(0);
+    if ( this->frequence > 50.0f ) {                                                              //Define the max frequence value and check it.//
+       this->analogOut->write(0);                                                                 //If >max value, output 0.//
     } 
 }
 
-void SquareApp::stop()
+void SquareApp::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 SquareApp::setamplitude(float newamplitude)
+void SquareApp::setamplitude(float newamplitude)                                                  //(Overriden) Method that could set amplitude.//
 {
-    this->amplitude = newamplitude;
+    this->amplitude = newamplitude;                                                               //Set the new amplitude.//
 }
-void SquareApp::setfrequence(float newfrequence)
+void SquareApp::setfrequence(float newfrequence)                                                  //(Overriden) Method that could set frequence.//
 {
-    this->frequence = newfrequence;
+    this->frequence = newfrequence;                                                               //Set the new frequence.//
 }