JIAWEI ZHANG / Mbed 2 deprecated ele350ku

Dependencies:   mbed

Dependents:   Exercise8_1-2-3

Fork of ele350 by JIAWEI ZHANG

Committer:
GGHHHH
Date:
Fri Dec 18 16:30:49 2015 +0000
Revision:
56:49640c23b101
Parent:
55:2260345179e1
Child:
57:53e6a0e9825c
f

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GGHHHH 29:8ec9451b1a59 1 #include "sine_app.h"
GGHHHH 54:aee1b44e62ec 2
GGHHHH 54:aee1b44e62ec 3 //Constructor. Calls the bass class (App) constructor and creact an AnalogOut object.//
GGHHHH 29:8ec9451b1a59 4 SineApp::SineApp(Serial* serial) : App("Sine wave", serial) {
GGHHHH 54:aee1b44e62ec 5 //Set analogOut attribute to a new AnalogOut object.//
GGHHHH 29:8ec9451b1a59 6 this->analogOut = new AnalogOut (PA_4);
GGHHHH 54:aee1b44e62ec 7 this->amplitude = 3.0f; //Set the amplitude value.//
GGHHHH 54:aee1b44e62ec 8 this->frequence = 50.0f; //Set the frequence value.//
GGHHHH 29:8ec9451b1a59 9 }
GGHHHH 29:8ec9451b1a59 10
GGHHHH 54:aee1b44e62ec 11 void SineApp::start() //(Overriden) Method that runs when the app starts.//
GGHHHH 54:aee1b44e62ec 12 {
GGHHHH 54:aee1b44e62ec 13 App::start(); //Call bass class's start() method.//
GGHHHH 54:aee1b44e62ec 14 this->analogOut->write(this->amplitude/3.0f); //Set the output to the amplitude.//
GGHHHH 54:aee1b44e62ec 15 this->timer.start(); //Start timer.//
GGHHHH 54:aee1b44e62ec 16 if ( this->amplitude > 3.0f ) { //Define the max amplitude value and check it.//
GGHHHH 54:aee1b44e62ec 17 this->analogOut->write(0); //If >max value, output 0.//
GGHHHH 54:aee1b44e62ec 18 } else { this->analogOut->write(this->amplitude/3.0f);} //If <max value, out the right expression.//
GGHHHH 29:8ec9451b1a59 19
GGHHHH 29:8ec9451b1a59 20 }
GGHHHH 29:8ec9451b1a59 21
GGHHHH 54:aee1b44e62ec 22 void SineApp::run() //(Overriden) Method that is called repeatedly when the app starts.//
GGHHHH 29:8ec9451b1a59 23 {
GGHHHH 56:49640c23b101 24 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.//
GGHHHH 47:124bc7d77d5a 25
GGHHHH 54:aee1b44e62ec 26 if ( this->frequence > 50.0f ) { //Define the max frequence value and check it.//
GGHHHH 54:aee1b44e62ec 27 this->analogOut->write(0); //If >max value, output 0.//
GGHHHH 54:aee1b44e62ec 28 } 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.//
GGHHHH 29:8ec9451b1a59 29
GGHHHH 34:498a218cf53e 30
GGHHHH 29:8ec9451b1a59 31 }
GGHHHH 29:8ec9451b1a59 32
GGHHHH 54:aee1b44e62ec 33 void SineApp::stop() //(Overriden) Method that runs when the app stops.//
GGHHHH 29:8ec9451b1a59 34 {
GGHHHH 54:aee1b44e62ec 35 App::stop(); //Call bass class's stop() method.//
GGHHHH 54:aee1b44e62ec 36 this->analogOut->write(0.0f); //Set output to 0V.//
GGHHHH 54:aee1b44e62ec 37 this->timer.stop(); //Stop the time and reset it.//
GGHHHH 29:8ec9451b1a59 38 this->timer.reset();
GGHHHH 34:498a218cf53e 39 }
GGHHHH 54:aee1b44e62ec 40 void SineApp::setamplitude(float newamplitude) //(Overriden) Method that could set amplitude.//
GGHHHH 34:498a218cf53e 41 {
GGHHHH 54:aee1b44e62ec 42 this->amplitude = newamplitude; //Set the new amplitude.//
GGHHHH 39:ab2557044815 43 }
GGHHHH 54:aee1b44e62ec 44 void SineApp::setfrequence(float newfrequence) //(Overriden) Method that could set frequence.//
GGHHHH 39:ab2557044815 45 {
GGHHHH 54:aee1b44e62ec 46 this->frequence = newfrequence; //Set the new frequence.//
GGHHHH 39:ab2557044815 47 }