ARDUINO 328 Functions Joysticks
From ROBOTC API Guide
| Line 19: | Line 19: | ||
if(joystick.joy1_Buttons & 0x01) //Check if button 1 from the button bit-mask is pressed. | if(joystick.joy1_Buttons & 0x01) //Check if button 1 from the button bit-mask is pressed. | ||
| − | + | motor[servo_9] = 50; | |
if(joystick.joy1_TopHat == 0) //Check if the tophat is pressed in the up direction. | if(joystick.joy1_TopHat == 0) //Check if the tophat is pressed in the up direction. | ||
| − | + | motor[servo_9] = -50; | |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 06:45, 15 May 2012
ARDUINO → Functions and Variables → 328 Joystick
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; //Create the 'joystick' structure to store joystick data. while(true) { getPCJoystickSettings(joystick); //Get the latest data from the joysticks and update the structure. motor[servo_2] = joystick.joy1_y1; //Assign a motor the value of a joystick axis motor[servo_3] = joystick.joy1_y2; //Assign a motor the value of a joystick axis if(joystick.joy1_Buttons & 0x01) //Check if button 1 from the button bit-mask is pressed. motor[servo_9] = 50; if(joystick.joy1_TopHat == 0) //Check if the tophat is pressed in the up direction. motor[servo_9] = -50; }
|
| |||||||
getPCJoystickSettings
| getPCJoystickSettings(TPCJoystick &joystick) | ||||||
| (void) Before you can use the joystick variables, you have to "update" the variables by getting the newest packet of data from the joysticks. Because the joystick station may only send updates every 50-100ms, you should update your joystick values as often as possible to get the most up to date joystick data. To "update" your joystick variables, use this function. | ||||||
| ||||||
|
TPCJoystick Structure Members
joy1_Buttons
| TPCJoystick joy1_Buttons | |
| (TPCJoystick) Returns a "Bit Map" for the 12 buttons on Controller #1. | |
|
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. | |
|
