
leitura simples do joystick
Dependencies: mbed
main.cpp@0:376d8f995739, 2019-04-23 (annotated)
- Committer:
- rebecams
- Date:
- Tue Apr 23 13:52:21 2019 +0000
- Revision:
- 0:376d8f995739
joystick leitura simples
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rebecams | 0:376d8f995739 | 1 | #include "mbed.h" |
rebecams | 0:376d8f995739 | 2 | |
rebecams | 0:376d8f995739 | 3 | #define T_MS 500 // Define the time between reads |
rebecams | 0:376d8f995739 | 4 | #define VRx A0 // Define the input pin for VRx pin |
rebecams | 0:376d8f995739 | 5 | #define VRy A1 // Define the input pin for VRy pin |
rebecams | 0:376d8f995739 | 6 | #define SW D5 // Define the input pin for SW pin |
rebecams | 0:376d8f995739 | 7 | |
rebecams | 0:376d8f995739 | 8 | int main() |
rebecams | 0:376d8f995739 | 9 | { |
rebecams | 0:376d8f995739 | 10 | AnalogIn x_axis(VRx); // Create the analog x movement object |
rebecams | 0:376d8f995739 | 11 | AnalogIn y_axis(VRy); // Create the analog y movement object |
rebecams | 0:376d8f995739 | 12 | DigitalIn button(SW, PullUp); // Create the digital button object and setup internall pull-up resistor |
rebecams | 0:376d8f995739 | 13 | |
rebecams | 0:376d8f995739 | 14 | while(1) |
rebecams | 0:376d8f995739 | 15 | { |
rebecams | 0:376d8f995739 | 16 | printf("\n"); |
rebecams | 0:376d8f995739 | 17 | printf("\n X axis: %f", x_axis.read()); // Show the value of the X axis (0.0 to 1.0) |
rebecams | 0:376d8f995739 | 18 | printf("\n Y axis: %f", y_axis.read()); // Show the value of the Y axis (0.0 to 1.0) |
rebecams | 0:376d8f995739 | 19 | printf("\n Button: %d", button.read()); // Show the button status (0 is pressed, 1 is not pressed) |
rebecams | 0:376d8f995739 | 20 | |
rebecams | 0:376d8f995739 | 21 | wait_ms(T_MS); // Wait time between reads |
rebecams | 0:376d8f995739 | 22 | } |
rebecams | 0:376d8f995739 | 23 | } |