Difference between revisions of "ARDUINO MEGA Functions Joysticks"
From ROBOTC API Guide
(→Controller 1) |
|||
Line 40: | Line 40: | ||
getJoystickSettings(joystick); // update buttons and joysticks | getJoystickSettings(joystick); // update buttons and joysticks | ||
− | if(joystick.joy1_Buttons | + | if(joystick.joy1_Buttons & 0x20) // if Button 6 is pressed on joy1: |
{ | { | ||
− | motor[ | + | motor[servo_2] = 50; // servo_2 is run at a power level of 50 |
} | } | ||
} | } | ||
Line 69: | Line 69: | ||
if(joystick.joy1_TopHat == 0) // if the topmost button on joy1's D-Pad ('TopHat') is pressed: | if(joystick.joy1_TopHat == 0) // if the topmost button on joy1's D-Pad ('TopHat') is pressed: | ||
{ | { | ||
− | motor[ | + | motor[servo_2] = 50; // servo_2 is run at a power level of 50 |
} | } | ||
} | } | ||
Line 93: | Line 93: | ||
{ | { | ||
getJoystickSettings(joystick); // update buttons and joysticks | getJoystickSettings(joystick); // update buttons and joysticks | ||
− | motor[ | + | motor[servo_2] = joystick.joy1_x1; // servo_2's powerlevel is set to the left stick's current x-value |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 116: | Line 116: | ||
{ | { | ||
getJoystickSettings(joystick); // update buttons and joysticks | getJoystickSettings(joystick); // update buttons and joysticks | ||
− | motor[ | + | motor[servo_2] = joystick.joy1_y1; // servo_2's powerlevel is set to the left stick's current y-value |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 139: | Line 139: | ||
{ | { | ||
getJoystickSettings(joystick); // update buttons and joysticks | getJoystickSettings(joystick); // update buttons and joysticks | ||
− | motor[ | + | motor[servo_2] = joystick.joy1_x2; // servo_2's powerlevel is set to the right stick's current x-value |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 162: | Line 162: | ||
{ | { | ||
getJoystickSettings(joystick); // update buttons and joysticks | getJoystickSettings(joystick); // update buttons and joysticks | ||
− | motor[ | + | motor[servo_2] = joystick.joy1_y2; // servo_2's powerlevel is set the right stick's current y-value |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 01:47, 10 May 2012
ARDUINO → Functions and Variables → ARDUINO MEGA Functions Joysticks
The Arduino supports a USB based joystick to send data from the PC over the USB link to the controller. You can access the joysticks by opening the "Joystick Control - Basic" joystick debugger window. For more information, see the different variables the joystick data will populate to below.
Example Code:
TPCJoystick joystick; getPCJoystickSettings(joystick); while(true) { motor[servo_2] = joystick.joy1_y1; motor[servo_3] = joystick.joy1_y2; if(joystick.joy1_Buttons & 0x01) writeDebugStream("Button 1 Pressed"); if(joystick.joy1_TopHat == 0) writeDebugStream("Top of TopHat Pressed"); }
|
Controller 1
joy1_Buttons
TPCJoystick joy1_Buttons | |
(TPCJoystick) Returns a "Bit Map" for the 12 buttons on Controller #1. For more information on how to use buttons to control actions, See the "Using Buttons" help section. | |
|
joy1_TopHat
TPCJoystick joy1_TopHat | |
(TPCJoystick) Returns the value of the direction pad (or "Top Hat") on Controller #1. A value of -1 is returned when nothing is pressed, and a value of 0 to 7 for selected "octant" when pressed. | |
|
joy1_x1
TPCJoystick joy1_x1 | |
(TPCJoystick) Value of the X Axis on the Left Joystick on Controller #1. Ranges in values between -128 to +127. | |
|
joy1_y1
TPCJoystick joy1_y1 | |
(TPCJoystick) Value of the Y Axis on the Left Joystick on Controller #1. Ranges in values between -128 to +127. | |
|
joy1_x2
TPCJoystick joy1_x2 | |
(TPCJoystick) Value of the X Axis on the Right Joystick on Controller #1. Ranges in values between -128 to +127. | |
|
joy1_y2
TPCJoystick joy1_y2 | |
(TPCJoystick) Value of the Y Axis on the Right Joystick on Controller #1. Ranges in values between -128 to +127. | |
|