elec350

Dependencies:   mbed

Fork of elec350 by Bob Merrison-Hort

button.cpp

Committer:
rmerrisonhort
Date:
2015-10-14
Revision:
3:998b7d011f2a
Parent:
0:753cf4c2738f
Child:
4:549d1d8ca969

File content as of revision 3:998b7d011f2a:

#include "button.h"

Button::Button(string name)
{
    if (name == "user") {
        this->pin = new DigitalIn(PA_0);
    }
}

bool Button::isPressed()
{
    if (this->pin->read() == 1) {
        return true;
    } else {
        return false;
    }
}

float Button::waitWhileHeld()
{
    const float waitInterval = 0.1f;
    while(this->isPressed() == false) {
        wait(waitInterval);
    }
    
    float heldTime = 0.0f;
    while(this->isPressed() == true) {
        heldTime += waitInterval;
        wait(waitInterval);
    }
    
    return heldTime;
}