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
- Committer:
- GGHHHH
- Date:
- 2015-12-17
- Revision:
- 42:6eb557ade29c
- Parent:
- 41:db959505e044
- Child:
- 43:b45ede0e3ba6
File content as of revision 42:6eb557ade29c:
#include "square_app.h"
SquareApp::SquareApp(Serial* serial) : App("Square wave", serial) {
this->analogOut = new AnalogOut (PA_4);
this->amplitude = 2.95f;
this->frequence = 50.0f;
}
void SquareApp::start()
{
App::start();
this->analogOut->write(this->amplitude/2.95f);
this->timer.start();
}
void SquareApp::run()
{
float p;
p = (frequence*timer.read())-floor(frequence*timer.read());
if ( p < 0.5f ) {
this->analogOut->write(0);
} else { this->analogOut->write(this->amplitude/2.95f);}
float frequence;
frequence = 50.0f;
if ( frequence > 50.0f ) {
this->analogOut->write(0);
} else { this->analogOut->write(this->amplitude/2.95f);}
float amplitude;
amplitude = 2.95;
if ( amplitude > 2.95f ) {
this->analogOut->write(0);
} else { this->analogOut->write(this->amplitude/2.95f);}
}
void SquareApp::stop()
{
App::stop();
this->analogOut->write(0.0f);
this->timer.stop();
this->timer.reset();
}
void SquareApp::setamplitude(float newamplitude)
{
this->amplitude = newamplitude;
}
void SquareApp::setfrequence(float newfrequence)
{
this->frequence = newfrequence;
}
