Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ele350 by
square_app.cpp@42:6eb557ade29c, 2015-12-17 (annotated)
- Committer:
- GGHHHH
- Date:
- Thu Dec 17 16:15:42 2015 +0000
- Revision:
- 42:6eb557ade29c
- Parent:
- 41:db959505e044
- Child:
- 43:b45ede0e3ba6
ok
Who changed what in which revision?
| User | Revision | Line number | New 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 | 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 | 42:6eb557ade29c | 23 | } else { this->analogOut->write(this->amplitude/2.95f);} |
| GGHHHH | 42:6eb557ade29c | 24 | float frequence; |
| GGHHHH | 42:6eb557ade29c | 25 | frequence = 50.0f; |
| GGHHHH | 42:6eb557ade29c | 26 | if ( frequence > 50.0f ) { |
| GGHHHH | 42:6eb557ade29c | 27 | this->analogOut->write(0); |
| GGHHHH | 42:6eb557ade29c | 28 | } else { this->analogOut->write(this->amplitude/2.95f);} |
| GGHHHH | 42:6eb557ade29c | 29 | float amplitude; |
| GGHHHH | 42:6eb557ade29c | 30 | amplitude = 2.95; |
| GGHHHH | 42:6eb557ade29c | 31 | if ( amplitude > 2.95f ) { |
| 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 | } |
