JIAWEI ZHANG / Mbed 2 deprecated ele350ku

Dependencies:   mbed

Dependents:   Exercise8_1-2-3

Fork of ele350 by JIAWEI ZHANG

square_app.cpp

Committer:
GGHHHH
Date:
2015-12-18
Revision:
49:da7b177b5245
Parent:
48:a72a8624bf2d
Child:
50:daa64b483569

File content as of revision 49:da7b177b5245:

#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(); 
    if ( this->amplitude > 2.95f ) {
       this->analogOut->write(0);
    } else { this->analogOut->write(this->amplitude/2.95f);}

}

void SquareApp::run()
{
   float p;
   p = (this->frequence*timer.read())-floor(this->frequence*timer.read());
   if ( p < 0.5f ) {
       this->analogOut->write(0);
    } else { this->analogOut->write(this->amplitude/2.95f);} 
    
    if ( this->frequence > 50.0f ) {
       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;
}