Code:
static char p1_trig_state = 1;
static unsigned char p1_trig_pressed = 0;
if(p1_sw_trig && !p1_trig_pressed) {
p1_trig_state *= -1;
p1_trig_pressed = 1;
}
else if(!p1_sw_trig)
p1_trig_pressed = 0;
if(p1_trig_state==1)
pwm01 = 255;
else
pwm01 = 127;
with any toggle code, if your output switches state rapidly a few times after your input is pressed, you might need to add a little delay to debounce the input