Last active
December 12, 2016 23:40
-
-
Save johnholbrook/5d5cb1bb74506e94903fcce328e07cd7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /************************************************************ | |
| Joystick Dead-zone Example Code | |
| John Holbrook, December 2016 | |
| Writen for VRC 8768, Huntington High School | |
| ************************************************************/ | |
| //set the radius here (put this near the top of your file) | |
| #define DEAD_ZONE_RADIUS 20 | |
| task main() | |
| { | |
| //initialize these at the top of the main() task | |
| int vexRT1, vexRT2, vexRT3, vexRT4; | |
| while (true){//this is just the normal infinite loop in which all your control code runs | |
| //at the top of the loop we define the values of the integers declared above, | |
| //which will be the joystick raw values if they are within DEAD_ZONE_RADIUS of the center, | |
| //or 0 otherwise. I used ternary operators in order to do each channel in one line, | |
| //but you could just as well use a series of if/else statements | |
| vexRT1 = abs(vexRT[Ch1]) <= DEAD_ZONE_RADIUS ? 0 : vexRT[Ch1]; | |
| vexRT2 = abs(vexRT[Ch2]) <= DEAD_ZONE_RADIUS ? 0 : vexRT[Ch2]; | |
| vexRT3 = abs(vexRT[Ch3]) <= DEAD_ZONE_RADIUS ? 0 : vexRT[Ch3]; | |
| vexRT4 = abs(vexRT[Ch4]) <= DEAD_ZONE_RADIUS ? 0 : vexRT[Ch4]; | |
| //so now we just use those integer values in place of the directly-read joystick values | |
| //in our control code. For example: | |
| motor[left_drive] = vexRT3; | |
| motor[right_drive] = vexRT2; | |
| //or whatever... | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment