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:31:52 2015 +0000
Revision:
49:da7b177b5245
Parent:
48:a72a8624bf2d
Child:
50:daa64b483569
gd

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 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 SquareApp::run()
GGHHHH 29:8ec9451b1a59 21 {
GGHHHH 35:6855566cc941 22 float p;
GGHHHH 46:efa9285bf105 23 p = (this->frequence*timer.read())-floor(this->frequence*timer.read());
GGHHHH 38:8d1e47006b2c 24 if ( p < 0.5f ) {
GGHHHH 35:6855566cc941 25 this->analogOut->write(0);
GGHHHH 42:6eb557ade29c 26 } else { this->analogOut->write(this->amplitude/2.95f);}
GGHHHH 47:124bc7d77d5a 27
GGHHHH 47:124bc7d77d5a 28 if ( this->frequence > 50.0f ) {
GGHHHH 42:6eb557ade29c 29 this->analogOut->write(0);
GGHHHH 42:6eb557ade29c 30 } else { this->analogOut->write(this->amplitude/2.95f);}
GGHHHH 29:8ec9451b1a59 31 }
GGHHHH 29:8ec9451b1a59 32
GGHHHH 29:8ec9451b1a59 33 void SquareApp::stop()
GGHHHH 29:8ec9451b1a59 34 {
GGHHHH 29:8ec9451b1a59 35 App::stop();
GGHHHH 35:6855566cc941 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 SquareApp::setamplitude(float newamplitude)
GGHHHH 34:498a218cf53e 41 {
GGHHHH 34:498a218cf53e 42 this->amplitude = newamplitude;
GGHHHH 40:ca1789c40924 43 }
GGHHHH 40:ca1789c40924 44 void SquareApp::setfrequence(float newfrequence)
GGHHHH 40:ca1789c40924 45 {
GGHHHH 40:ca1789c40924 46 this->frequence = newfrequence;
GGHHHH 40:ca1789c40924 47 }