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-17
Revision:
41:db959505e044
Parent:
40:ca1789c40924
Child:
42:6eb557ade29c

File content as of revision 41:db959505e044:

#include "square_app.h"

SquareApp::SquareApp(Serial* serial) : App("Square wave", serial) {
    this->analogOut = new AnalogOut (PA_4);
    this->amplitude = 3.0f;
    this->frequence = 50.0f;
}

void SquareApp::start()
{
    App::start();
    this->analogOut->write(this->amplitude/3.0f);
    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/3.0f);} 
}

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;
}