Digital Joystick
Joystick.h@5:31e3324d4c4b, 2015-02-21 (annotated)
- Committer:
- LeoHsueh
- Date:
- Sat Feb 21 05:20:01 2015 +0000
- Revision:
- 5:31e3324d4c4b
- Parent:
- 3:83b40e07476f
- Child:
- 6:d354f6e3bd9b
joy lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alex89_2 | 0:9c486d50434e | 1 | //remove repetition |
alex89_2 | 0:9c486d50434e | 2 | #ifndef MBED_JOYSTICK_H |
alex89_2 | 0:9c486d50434e | 3 | #define MBED_JOYSTICK_H |
alex89_2 | 0:9c486d50434e | 4 | |
alex89_2 | 0:9c486d50434e | 5 | //required to use mbed functions |
alex89_2 | 0:9c486d50434e | 6 | #include "mbed.h" |
alex89_2 | 0:9c486d50434e | 7 | |
LeoHsueh | 5:31e3324d4c4b | 8 | #define JOY_UP 0x01 |
LeoHsueh | 5:31e3324d4c4b | 9 | #define JOY_DOWN 0x02 |
LeoHsueh | 5:31e3324d4c4b | 10 | #define JOY_LEFT 0x04 |
LeoHsueh | 5:31e3324d4c4b | 11 | #define JOY_RIGHT 0x08 |
LeoHsueh | 5:31e3324d4c4b | 12 | #define JOY_PRESS 0x10 |
alex89_2 | 0:9c486d50434e | 13 | |
alex89_2 | 1:e55694d8a418 | 14 | /** Class: Joystick |
alex89_2 | 2:8805f880e231 | 15 | * |
LeoHsueh | 5:31e3324d4c4b | 16 | * Used for reading from an digital joystick |
alex89_2 | 0:9c486d50434e | 17 | * |
alex89_2 | 0:9c486d50434e | 18 | * Example: |
alex89_2 | 2:8805f880e231 | 19 | * |
alex89_2 | 0:9c486d50434e | 20 | * > #include "mbed.h" |
alex89_2 | 2:8805f880e231 | 21 | * |
LeoHsueh | 5:31e3324d4c4b | 22 | * > Joystick joystick(P2_3, P0_15, P2_4, P0_16, P0_17); |
alex89_2 | 0:9c486d50434e | 23 | */ |
alex89_2 | 0:9c486d50434e | 24 | |
LeoHsueh | 5:31e3324d4c4b | 25 | class Joystick { |
LeoHsueh | 5:31e3324d4c4b | 26 | public: |
LeoHsueh | 5:31e3324d4c4b | 27 | /** Create a Joystick HID for using regular mbed pins |
LeoHsueh | 5:31e3324d4c4b | 28 | * |
LeoHsueh | 5:31e3324d4c4b | 29 | * @param up Joystick Up |
LeoHsueh | 5:31e3324d4c4b | 30 | * @param down Joystick Down |
LeoHsueh | 5:31e3324d4c4b | 31 | * @param left Joystick Left |
LeoHsueh | 5:31e3324d4c4b | 32 | * @param right Joystick Right |
LeoHsueh | 5:31e3324d4c4b | 33 | * @param press Joystick Press |
LeoHsueh | 5:31e3324d4c4b | 34 | */ |
LeoHsueh | 5:31e3324d4c4b | 35 | Joystick(PinName up, PinName down, PinName left, PinName right, PinName press); |
alex89_2 | 0:9c486d50434e | 36 | |
LeoHsueh | 5:31e3324d4c4b | 37 | /** Function: getStatus |
LeoHsueh | 5:31e3324d4c4b | 38 | * Read the joystick status |
LeoHsueh | 5:31e3324d4c4b | 39 | * |
LeoHsueh | 5:31e3324d4c4b | 40 | * Variables: |
LeoHsueh | 5:31e3324d4c4b | 41 | * returns - A uint8_t values representing the bits |
LeoHsueh | 5:31e3324d4c4b | 42 | */ |
LeoHsueh | 5:31e3324d4c4b | 43 | uint8_t getStatus(); |
LeoHsueh | 5:31e3324d4c4b | 44 | |
LeoHsueh | 5:31e3324d4c4b | 45 | private: |
LeoHsueh | 5:31e3324d4c4b | 46 | |
LeoHsueh | 5:31e3324d4c4b | 47 | /** Regular mbed pins bus |
LeoHsueh | 5:31e3324d4c4b | 48 | */ |
LeoHsueh | 5:31e3324d4c4b | 49 | DigitalIn _up, _down, _left, _right, _press; |
alex89_2 | 0:9c486d50434e | 50 | }; |
alex89_2 | 0:9c486d50434e | 51 | |
LeoHsueh | 5:31e3324d4c4b | 52 | #endif |