Jose Rios
/
Nucleo_JoystickAnalogPad
Reading values from joystick analog pad (Keyes_SJoys)
main.cpp@0:36cb6ee1fec3, 2014-09-19 (annotated)
- Committer:
- jose_23991
- Date:
- Fri Sep 19 13:35:08 2014 +0000
- Revision:
- 0:36cb6ee1fec3
Revision 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jose_23991 | 0:36cb6ee1fec3 | 1 | #include "mbed.h" |
jose_23991 | 0:36cb6ee1fec3 | 2 | |
jose_23991 | 0:36cb6ee1fec3 | 3 | #define T_MS 500 // Define the time between reads |
jose_23991 | 0:36cb6ee1fec3 | 4 | #define VRx A0 // Define the input pin for VRx pin |
jose_23991 | 0:36cb6ee1fec3 | 5 | #define VRy A1 // Define the input pin for VRy pin |
jose_23991 | 0:36cb6ee1fec3 | 6 | #define SW D2 // Define the input pin for SW pin |
jose_23991 | 0:36cb6ee1fec3 | 7 | |
jose_23991 | 0:36cb6ee1fec3 | 8 | int main() |
jose_23991 | 0:36cb6ee1fec3 | 9 | { |
jose_23991 | 0:36cb6ee1fec3 | 10 | AnalogIn x_axis(VRx); // Create the analog x movement object |
jose_23991 | 0:36cb6ee1fec3 | 11 | AnalogIn y_axis(VRy); // Create the analog y movement object |
jose_23991 | 0:36cb6ee1fec3 | 12 | DigitalIn button(SW, PullUp); // Create the digital button object and setup internall pull-up resistor |
jose_23991 | 0:36cb6ee1fec3 | 13 | |
jose_23991 | 0:36cb6ee1fec3 | 14 | while(1) |
jose_23991 | 0:36cb6ee1fec3 | 15 | { |
jose_23991 | 0:36cb6ee1fec3 | 16 | printf("\n"); |
jose_23991 | 0:36cb6ee1fec3 | 17 | printf("\n X axis: %f", x_axis.read()); // Show the value of the X axis (0.0 to 1.0) |
jose_23991 | 0:36cb6ee1fec3 | 18 | printf("\n Y axis: %f", y_axis.read()); // Show the value of the Y axis (0.0 to 1.0) |
jose_23991 | 0:36cb6ee1fec3 | 19 | printf("\n Button: %d", button.read()); // Show the button status (0 is pressed, 1 is not pressed) |
jose_23991 | 0:36cb6ee1fec3 | 20 | |
jose_23991 | 0:36cb6ee1fec3 | 21 | wait_ms(T_MS); // Wait time between reads |
jose_23991 | 0:36cb6ee1fec3 | 22 | } |
jose_23991 | 0:36cb6ee1fec3 | 23 | } |