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:38:22 2015 +0000
Revision:
41:db959505e044
Parent:
39:ab2557044815
Child:
42:6eb557ade29c
k

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 36:a9f4a3409c89 5 this->amplitude = 3.0f;
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 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 SineApp::run()
GGHHHH 29:8ec9451b1a59 18 {
GGHHHH 41:db959505e044 19 this->analogOut->write(this->amplitude/3.0f*0.5f*(1.0f+sin(frequence*6.28f*timer.read())));
GGHHHH 29:8ec9451b1a59 20
GGHHHH 34:498a218cf53e 21
GGHHHH 29:8ec9451b1a59 22 }
GGHHHH 29:8ec9451b1a59 23
GGHHHH 29:8ec9451b1a59 24 void SineApp::stop()
GGHHHH 29:8ec9451b1a59 25 {
GGHHHH 29:8ec9451b1a59 26 App::stop();
GGHHHH 33:c084f49cd403 27 this->analogOut->write(0.0f);
GGHHHH 29:8ec9451b1a59 28 this->timer.stop();
GGHHHH 29:8ec9451b1a59 29 this->timer.reset();
GGHHHH 34:498a218cf53e 30 }
GGHHHH 34:498a218cf53e 31 void SineApp::setamplitude(float newamplitude)
GGHHHH 34:498a218cf53e 32 {
GGHHHH 34:498a218cf53e 33 this->amplitude = newamplitude;
GGHHHH 39:ab2557044815 34 }
GGHHHH 39:ab2557044815 35 void SineApp::setfrequence(float newfrequence)
GGHHHH 39:ab2557044815 36 {
GGHHHH 39:ab2557044815 37 this->frequence = newfrequence;
GGHHHH 39:ab2557044815 38 }