JIAWEI ZHANG / Mbed 2 deprecated ele350ku

Dependencies:   mbed

Dependents:   Exercise8_1-2-3

Fork of ele350 by JIAWEI ZHANG

Committer:
GGHHHH
Date:
Thu Dec 17 13:40:16 2015 +0000
Revision:
36:a9f4a3409c89
Parent:
35:6855566cc941
Child:
37:83b729ea17d4
s

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 36:a9f4a3409c89 5 this->amplitude = 3.0f;
GGHHHH 29:8ec9451b1a59 6 }
GGHHHH 29:8ec9451b1a59 7
GGHHHH 29:8ec9451b1a59 8 void SquareApp::start()
GGHHHH 29:8ec9451b1a59 9 {
GGHHHH 29:8ec9451b1a59 10 App::start();
GGHHHH 36:a9f4a3409c89 11 this->analogOut->write(this->amplitude/3.0f);
GGHHHH 29:8ec9451b1a59 12 this->timer.start();
GGHHHH 29:8ec9451b1a59 13
GGHHHH 29:8ec9451b1a59 14 }
GGHHHH 29:8ec9451b1a59 15
GGHHHH 29:8ec9451b1a59 16 void SquareApp::run()
GGHHHH 29:8ec9451b1a59 17 {
GGHHHH 35:6855566cc941 18 float p;
GGHHHH 35:6855566cc941 19 p = (20.0f*timer.read())-floor(20.0f*timer.read());
GGHHHH 35:6855566cc941 20 if ( p < 0.5) {
GGHHHH 35:6855566cc941 21 this->analogOut->write(0);
GGHHHH 35:6855566cc941 22 } else { this->analogOut->write(2.0/3.0);}
GGHHHH 29:8ec9451b1a59 23 }
GGHHHH 29:8ec9451b1a59 24
GGHHHH 29:8ec9451b1a59 25 void SquareApp::stop()
GGHHHH 29:8ec9451b1a59 26 {
GGHHHH 29:8ec9451b1a59 27 App::stop();
GGHHHH 35:6855566cc941 28 this->analogOut->write(0.0f);
GGHHHH 29:8ec9451b1a59 29 this->timer.stop();
GGHHHH 29:8ec9451b1a59 30 this->timer.reset();
GGHHHH 34:498a218cf53e 31 }
GGHHHH 34:498a218cf53e 32 void SquareApp::setamplitude(float newamplitude)
GGHHHH 34:498a218cf53e 33 {
GGHHHH 34:498a218cf53e 34 this->amplitude = newamplitude;
GGHHHH 29:8ec9451b1a59 35 }