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 14:21:26 2015 +0000
Revision:
40:ca1789c40924
Parent:
38:8d1e47006b2c
Child:
41:db959505e044
g

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