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 14:04:25 2015 +0000
Revision:
53:bbff5bff8b53
Parent:
52:c245d9c98de3
Child:
54:aee1b44e62ec
h

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 48:a72a8624bf2d 14 if ( this->amplitude > 2.95f ) {
GGHHHH 43:b45ede0e3ba6 15 this->analogOut->write(0);
GGHHHH 43:b45ede0e3ba6 16 } else { this->analogOut->write(this->amplitude/2.95f);}
GGHHHH 29:8ec9451b1a59 17
GGHHHH 29:8ec9451b1a59 18 }
GGHHHH 29:8ec9451b1a59 19
GGHHHH 29:8ec9451b1a59 20 void SineApp::run()
GGHHHH 29:8ec9451b1a59 21 {
GGHHHH 53:bbff5bff8b53 22 this->analogOut->write(this->amplitude+1.0f/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));
GGHHHH 47:124bc7d77d5a 23
GGHHHH 47:124bc7d77d5a 24 if ( this->frequence > 50.0f ) {
GGHHHH 46:efa9285bf105 25 this->analogOut->write(0);
GGHHHH 46:efa9285bf105 26 } else { this->analogOut->write(this->amplitude/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));}
GGHHHH 29:8ec9451b1a59 27
GGHHHH 34:498a218cf53e 28
GGHHHH 29:8ec9451b1a59 29 }
GGHHHH 29:8ec9451b1a59 30
GGHHHH 29:8ec9451b1a59 31 void SineApp::stop()
GGHHHH 29:8ec9451b1a59 32 {
GGHHHH 29:8ec9451b1a59 33 App::stop();
GGHHHH 33:c084f49cd403 34 this->analogOut->write(0.0f);
GGHHHH 29:8ec9451b1a59 35 this->timer.stop();
GGHHHH 29:8ec9451b1a59 36 this->timer.reset();
GGHHHH 34:498a218cf53e 37 }
GGHHHH 34:498a218cf53e 38 void SineApp::setamplitude(float newamplitude)
GGHHHH 34:498a218cf53e 39 {
GGHHHH 34:498a218cf53e 40 this->amplitude = newamplitude;
GGHHHH 39:ab2557044815 41 }
GGHHHH 39:ab2557044815 42 void SineApp::setfrequence(float newfrequence)
GGHHHH 39:ab2557044815 43 {
GGHHHH 39:ab2557044815 44 this->frequence = newfrequence;
GGHHHH 39:ab2557044815 45 }