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:28:07 2015 +0000
Revision:
48:a72a8624bf2d
Parent:
47:124bc7d77d5a
Child:
49:da7b177b5245
ok

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