
elec350
Fork of elec350 by
Diff: button.cpp
- Revision:
- 4:549d1d8ca969
- Parent:
- 3:998b7d011f2a
- Child:
- 6:1eee8ba927fe
--- a/button.cpp Wed Oct 14 21:09:51 2015 +0000 +++ b/button.cpp Thu Oct 15 16:34:35 2015 +0000 @@ -1,15 +1,25 @@ #include "button.h" +// Button constructor. Button::Button(string name) { + // Set the "pin" attribute to a DigitalIn object corresponding + // to the pin for the selected button (only one button at the + // moment. if (name == "user") { this->pin = new DigitalIn(PA_0); } } +// isPressed method: Return true if the button is currently pressed +// and false otherwise. bool Button::isPressed() { - if (this->pin->read() == 1) { + // Get current state of the pin. + int pinValue = this->pin->read(); + + // Check the value returned from this->pin->read() and return true or false. + if (pinValue == 1) { return true; } else { return false;