Input library for the STMstation P.1. Facilitates button state checking and battery voltage checking.
Library to check button states and battery voltage for the STMstation P.1.
See API documentation for detailed information.
Revision 1:8c73c4795f92, committed 2017-07-03
- Comitter:
- kkado
- Date:
- Mon Jul 03 09:24:06 2017 +0000
- Parent:
- 0:6951d1eef6ad
- Commit message:
- First public release.
Changed in this revision
STMstation_input.cpp | Show annotated file Show diff for this revision Revisions of this file |
STMstation_input.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6951d1eef6ad -r 8c73c4795f92 STMstation_input.cpp --- a/STMstation_input.cpp Thu Jun 22 09:06:57 2017 +0000 +++ b/STMstation_input.cpp Mon Jul 03 09:24:06 2017 +0000 @@ -3,7 +3,7 @@ STMstation_input::STMstation_input(): D_UP(UP_PIN), D_DOWN(DOWN_PIN), D_LEFT(LEFT_PIN), D_RIGHT(RIGHT_PIN), D_A(A_PIN), D_B(B_PIN), D_X(X_PIN), D_Y(Y_PIN), - D_START(START_PIN), D_SELECT(SELECT_PIN) + D_START(START_PIN), D_SELECT(SELECT_PIN), bat(BAT_PIN) { } @@ -64,4 +64,9 @@ else{ return 1; } +} + +float STMstation_input::batCheck(){ + float voltage = bat.read()*3.3f*159.0f/120; + return voltage; } \ No newline at end of file
diff -r 6951d1eef6ad -r 8c73c4795f92 STMstation_input.h --- a/STMstation_input.h Thu Jun 22 09:06:57 2017 +0000 +++ b/STMstation_input.h Mon Jul 03 09:24:06 2017 +0000 @@ -1,38 +1,46 @@ -/* -User input library for STMstation P.1 -Kevin Kadooka, June 2017 -*/ - #ifndef STMstation_input_h #define STMstation_input_h #include "mbed.h" -#define UP_PIN PA_0 -#define DOWN_PIN PC_3 -#define LEFT_PIN PC_2 -#define RIGHT_PIN PA_1 -#define A_PIN PB_10 -#define B_PIN PB_12 -#define X_PIN PB_1 -#define Y_PIN PB_2 +#define UP_PIN PA_0 +#define DOWN_PIN PC_3 +#define LEFT_PIN PC_2 +#define RIGHT_PIN PA_1 +#define A_PIN PB_10 +#define B_PIN PB_12 +#define X_PIN PB_1 +#define Y_PIN PB_2 #define START_PIN PB_4 #define SELECT_PIN PB_5 +#define BAT_PIN PC_0 + +/** Input library for the STMstation P.1 + * Provides information on button states (keydown, keyup, keypress) for each of the + * 10 user buttons (up, down, left, right, a, b, x, y, start, select). + */ class STMstation_input{ public: + ///Create an instance of STMstation_input STMstation_input(); enum Button {UP, DOWN, LEFT, RIGHT, A, B, X, Y, START, SELECT}; + ///Update the state of all buttons void updateButtons(); + ///Check if a keydown event has occurred bool keyDown(Button b); + ///Check if a keyup event has occurred bool keyUp(Button b); + ///Check if a button is pressed bool keyPress(Button b); + ///Check battery voltage + float batCheck(); private: - void init(); bool buttonPress[10]; bool buttonDown[10]; bool buttonUp[10]; DigitalIn D_UP, D_DOWN, D_LEFT, D_RIGHT, D_A, D_B, D_X, D_Y, D_START, D_SELECT; + AnalogIn bat; }; #endif \ No newline at end of file