First of all, instead of just setting 60 in the code, wouldn’t it be easier to #define it at the start of the code? That way if you want to change it, you can just change it there and don’t have to fish for it in the rest of the code.
#define Percent_Speed 60 //defines the percent of max speed you want to go
The #define sets the value of Percent_Speed (the percentage of max speed you want). Since in this case it is set to 60, Percent_Speed is equal to 60 throughout the code.
I’m assuming you’re saying this to prevent overflow when you multiply the value by 6, and also so that you can go into negative numbers when you subtract 127
Instead of declaring an int and wasting memory, why wouldn’t you just declare the variable as an unsigned short and typecast the variable during the operation?
unsigned short ourVariable;
declare the variable as an unsigned short
Assign it to your input(not shown here).
ourVariable = (((int)ourVariable - 127) * Percent_Speed / 10) + 127; //calculations
motor = ourVariable; //output ourVariable to motor.
If you change motor to whatever the motor you want to output to, the code will take ourVariable, which you have mapped to your input earlier in the code and typecast it into an integer for that operation only (see below). It will then multiply ourVariable by the percentage of your speed and divide by 10 to reduce the power to the percent you set in #define Percent_Speed, add your 127 back to get the value within the accepted range again, and set it to your motor. And yes, I realize I have a pair of unneeded parenthesis in the line, but I like grouping things that way.
Inserting (int) in front of ourVariable makes the program treat ourVariable as an integer for that operation (to give it room to perform the operation), but once the operation is done, ourVariable will return to a nice little unsigned char that doesn’t hog memory.