Instead of using variables as in l0jec's example, you could use #define statements to reduce memory usage and potentially speed up the program execution some. With a #define statement, the compiler in RobotC will replace all instances of 'MAX_JOY_VAL', for instance, with the value defined in the statement. The robot will see the defined values and not the names for the values defined in the statements. Be sure not to use either equals signs or semicolons in these lines.
Here's the same code he posted, except with #define statments:
Code:
int simpleScale(int joyVal) {
#define MAX_JOY_VAL 127
#define MAX_MOTOR_VAL 100
#define DEADZONE 5
//check for deadzone
if(abs(joyVal) < DEADZONE) {
return 0;
}
//calculate ratio based on max motor speed and max analog stick value
float ratio = (MAX_MOTOR_VAL/MAX_JOY_VAL);
//apply ratio to actual joystick value
int result = (joyVal)*ratio;
return result;
}