Oscar Schofield / Mbed 2 deprecated Elec350_OBS

Dependencies:   mbed

button.cpp

Committer:
Oschofield
Date:
2015-11-12
Revision:
13:4b9c32ba0572
Parent:
12:08a1971c9441
Child:
14:6427883f5900

File content as of revision 13:4b9c32ba0572:

#include "button.h" //header file included


Button::Button(string s){
    if (s == "user"){
        pin = new DigitalIn(PA_0);
    }
}

bool Button::ifPressed(){
    return *pin;
}

float Button::getPulse(float timeout)
{

    Timer timer;
    timer.start();
    
    while(this->ifPressed()== false){
        if (timeout != -1.0f && timer.read() > timeout){
            return -1.0f;
         }
    }
    
    while(this->ifPressed() == true){
        wait(0.01f);
    }
    
    timer.stop();
    return timer.read();    
}