
elec350
Fork of elec350 by
Diff: button.cpp
- Revision:
- 0:753cf4c2738f
- Child:
- 3:998b7d011f2a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/button.cpp Tue Oct 13 01:10:14 2015 +0000 @@ -0,0 +1,31 @@ +#include "button.h" + +Button::Button() +{ + 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; +} \ No newline at end of file