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 "square_app.h"
GGHHHH 29:8ec9451b1a59 2
GGHHHH 29:8ec9451b1a59 3 SquareApp::SquareApp(Serial* serial) : App("Square 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 SquareApp::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 SquareApp::run()
GGHHHH 29:8ec9451b1a59 23 {
GGHHHH 35:6855566cc941 24 float p;
GGHHHH 46:efa9285bf105 25 p = (this->frequence*timer.read())-floor(this->frequence*timer.read());
GGHHHH 38:8d1e47006b2c 26 if ( p < 0.5f ) {
GGHHHH 35:6855566cc941 27 this->analogOut->write(0);
GGHHHH 42:6eb557ade29c 28 } else { this->analogOut->write(this->amplitude/2.95f);}
GGHHHH 42:6eb557ade29c 29 float frequence;
GGHHHH 42:6eb557ade29c 30 frequence = 50.0f;
GGHHHH 42:6eb557ade29c 31 if ( frequence > 50.0f ) {
GGHHHH 42:6eb557ade29c 32 this->analogOut->write(0);
GGHHHH 42:6eb557ade29c 33 } else { this->analogOut->write(this->amplitude/2.95f);}
GGHHHH 29:8ec9451b1a59 34 }
GGHHHH 29:8ec9451b1a59 35
GGHHHH 29:8ec9451b1a59 36 void SquareApp::stop()
GGHHHH 29:8ec9451b1a59 37 {
GGHHHH 29:8ec9451b1a59 38 App::stop();
GGHHHH 35:6855566cc941 39 this->analogOut->write(0.0f);
GGHHHH 29:8ec9451b1a59 40 this->timer.stop();
GGHHHH 29:8ec9451b1a59 41 this->timer.reset();
GGHHHH 34:498a218cf53e 42 }
GGHHHH 34:498a218cf53e 43 void SquareApp::setamplitude(float newamplitude)
GGHHHH 34:498a218cf53e 44 {
GGHHHH 34:498a218cf53e 45 this->amplitude = newamplitude;
GGHHHH 40:ca1789c40924 46 }
GGHHHH 40:ca1789c40924 47 void SquareApp::setfrequence(float newfrequence)
GGHHHH 40:ca1789c40924 48 {
GGHHHH 40:ca1789c40924 49 this->frequence = newfrequence;
GGHHHH 40:ca1789c40924 50 }