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 13:06:26 2015 +0000
Revision:
46:efa9285bf105
Parent:
43:b45ede0e3ba6
Child:
47:124bc7d77d5a
kk

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GGHHHH 29:8ec9451b1a59 1 #include "sine_app.h"
GGHHHH 29:8ec9451b1a59 2
GGHHHH 29:8ec9451b1a59 3 SineApp::SineApp(Serial* serial) : App("Sine wave", serial) {
GGHHHH 29:8ec9451b1a59 4 this->analogOut = new AnalogOut (PA_4);
GGHHHH 42:6eb557ade29c 5 this->amplitude = 2.95f;
GGHHHH 41:db959505e044 6 this->frequence = 50.0f;
GGHHHH 29:8ec9451b1a59 7 }
GGHHHH 29:8ec9451b1a59 8
GGHHHH 29:8ec9451b1a59 9 void SineApp::start()
GGHHHH 29:8ec9451b1a59 10 {
GGHHHH 29:8ec9451b1a59 11 App::start();
GGHHHH 42:6eb557ade29c 12 this->analogOut->write(this->amplitude/2.95f);
GGHHHH 29:8ec9451b1a59 13 this->timer.start();
GGHHHH 43:b45ede0e3ba6 14 float amplitude;
GGHHHH 43:b45ede0e3ba6 15 amplitude = 2.95;
GGHHHH 43:b45ede0e3ba6 16 if ( amplitude > 2.95f ) {
GGHHHH 43:b45ede0e3ba6 17 this->analogOut->write(0);
GGHHHH 43:b45ede0e3ba6 18 } else { this->analogOut->write(this->amplitude/2.95f);}
GGHHHH 29:8ec9451b1a59 19
GGHHHH 29:8ec9451b1a59 20 }
GGHHHH 29:8ec9451b1a59 21
GGHHHH 29:8ec9451b1a59 22 void SineApp::run()
GGHHHH 29:8ec9451b1a59 23 {
GGHHHH 46:efa9285bf105 24 this->analogOut->write(this->amplitude/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));
GGHHHH 42:6eb557ade29c 25 float frequence;
GGHHHH 42:6eb557ade29c 26 frequence = 50.0f;
GGHHHH 42:6eb557ade29c 27 if ( frequence > 50.0f ) {
GGHHHH 46:efa9285bf105 28 this->analogOut->write(0);
GGHHHH 46:efa9285bf105 29 } else { this->analogOut->write(this->amplitude/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));}
GGHHHH 29:8ec9451b1a59 30
GGHHHH 34:498a218cf53e 31
GGHHHH 29:8ec9451b1a59 32 }
GGHHHH 29:8ec9451b1a59 33
GGHHHH 29:8ec9451b1a59 34 void SineApp::stop()
GGHHHH 29:8ec9451b1a59 35 {
GGHHHH 29:8ec9451b1a59 36 App::stop();
GGHHHH 33:c084f49cd403 37 this->analogOut->write(0.0f);
GGHHHH 29:8ec9451b1a59 38 this->timer.stop();
GGHHHH 29:8ec9451b1a59 39 this->timer.reset();
GGHHHH 34:498a218cf53e 40 }
GGHHHH 34:498a218cf53e 41 void SineApp::setamplitude(float newamplitude)
GGHHHH 34:498a218cf53e 42 {
GGHHHH 34:498a218cf53e 43 this->amplitude = newamplitude;
GGHHHH 39:ab2557044815 44 }
GGHHHH 39:ab2557044815 45 void SineApp::setfrequence(float newfrequence)
GGHHHH 39:ab2557044815 46 {
GGHHHH 39:ab2557044815 47 this->frequence = newfrequence;
GGHHHH 39:ab2557044815 48 }