A latching trigger

The code you posted suggests that you are using external pulldown resistors for the switches. Are you?

state is a lousy name for a variable. Something meaningful would be much better.

    state = 1 - state;
    state = 2 - state;

I can't figure out what state is supposed to be when this code is done. Or what it is supposed to represent. Or, how that works when state can supposedly have three values.

Why do you use the value of encoderPos and then check the encoder? I would think that it would make more sense to check the encoder first, then use encoderPos.