Working read code with mode button
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_senior_design_Testnew by
Diff: button.cpp
- Revision:
- 21:ceac47be2e64
- Parent:
- 16:581a3b02f4c3
- Child:
- 23:c5df903f068a
--- a/button.cpp Fri Oct 27 13:34:49 2017 +0000 +++ b/button.cpp Fri Oct 27 15:15:00 2017 +0000 @@ -3,7 +3,7 @@ // button constructor button::button(PwmOut servo, DigitalIn pb) - : servo(servo), pb(pb) {} + : servo(servo), pb(pb), press(0), state(0) {} //button::button(PwmOut servo, DigitalIn pb, AnalogIn lp) // : servo(servo), pb(pb), linpot(lp), mode(0), state(0) {} @@ -16,22 +16,28 @@ } // get servo pin -/*void button::setState(int mystate) +void button::setState(int mystate) { state = mystate; } // get servo pin -void button::setMode(int mymode) +/*void button::setMode(int mymode) { mode = mymode; }*/ // get current state of the button -/*int button::getState() +int button::getState() { return state; -}*/ +} + +int button::getPress() +{ + return press; +} + // move servo into the slot void button::moveServoIn() @@ -53,3 +59,36 @@ wait(0.01); } } + +int button::updateState() +{ + //myled = 0; + // state 0 - button is up, pb = 0 + if (pb == 0 && state == 3) { + // nothing happens here, servo is still + state = 0; + } + // state 1 - button is moving down, pb = 1 + if (pb == 1 && state == 0) { + moveServoIn(); + state = 1; + press = 1; + } + // state 2 - button is down, pb = 0 + if (pb == 0 && state == 1) { + // nothing happens here, servo is still + state = 2; + } + // state 3 - button is moving up, pb = 1 + if (pb == 1 && state == 2) { + moveServoOut(); + state = 3; + press = 0; + } + // state 4 - handle debouncing while button is down + /*if (pb1 = 1 && state == 2) { + count++; + }*/ + return state; +} +