I'd also move the pwm assignment to after the if statement. Otherwise, there will be an additional cycle delay in your response, since the pwm will reflect the old value from the if statement.
The my_y value could be defined as an unsigned character (8 bits) instead of int. It's not essential, but it is good practice to match variable types.
Code:
unsigned char my_y;
if (p3_sw_trig==1) {
my_y = p2_y;
}
else {
my_y = 127;
}
pwm02 = my_y;