Multiple mode selection with switch

Hello, i have a program that when you start it up it asks you to select a mode. You can chose between 2 modes. I only have 1 switch and after 5 seconds it will pick the selected mode. You can select the mode by pressing the switch. With each push on the switch the selector switches mode.

I have done this by checking the count value of the switch. When the value is an uqual number it selects mode 1, if the counter is unequal it selects mode 2.

I have done this like this:

if(counter & 0x01){
                mode = 2;
                LEDG_SetHigh();
                LEDR_SetHigh();
                __delay_ms(100);
                LEDR_SetLow();
                __delay_ms(100);
                LEDR_SetHigh();
                __delay_ms(100);
                LEDR_SetLow();
                __delay_ms(100);
                LEDR_SetHigh();
                __delay_ms(100);
            }
            
            else if(counter %2 == 0){
                mode = 3;
                LEDR_SetHigh();
                LEDG_SetHigh();
                __delay_ms(100);
                LEDG_SetLow();
                __delay_ms(100);
                LEDG_SetHigh();
                __delay_ms(100);
                LEDG_SetLow();
                __delay_ms(100);
                LEDG_SetHigh();
            }

But now i want to add a third mode. I dont know how to add this. My thought was to check for the table of numbers, for instance, if the pushbutton counter is 1, 4, 7,10 etc. mode 1 will be selected.
If the counter is 2,5,8,11 etc mode 2 will be selected
If the counter is 3,6,9,12 etc mode 3 will be selected.

How can i program this without writing huge lines of code? I dont want to say:
If(counter == 1 or counter ==4 or counter ==7){
mode = 1;
}

you get it?

You manufactured the problem by using counter intuitive and unnecessarily complex logic. Get rid of the disconnect between counter and mode, and ditch the "clever" modulo logic. Just increment the counter (same as mode), and use a switch/case statement to select the code you want to run for each mode.

For rollover from the last mode to the first, just check the bound when you increment it and reset it to the first if it reaches the end.

aarg:
Get rid of the disconnect between counter and mode, and ditch the "clever" modulo logic. Just increment the counter (same as mode), and use a switch/case statement to select the code you want to run for each mode.

Thanks, but im not sure if i get your idea. The switch/case statement also needs the buttoncounter value right?
The point is that you can keep selecting the modes after you reach the last mode. So if you push the button 3 times it will select mode 3, but if you push it again, it will select mode 1.

Killerpirate:
Thanks, but im not sure if i get your idea. The switch/case statement also needs the buttoncounter value right?
The point is that you can keep selecting the modes after you reach the last mode. So if you push the button 3 times it will select mode 3, but if you push it again, it will select mode 1.

Yes, the switch would use the counter value. So...

counter++;
if (counter > 3) counter = 1;

Also, it's not my idea. It's a standard technique that has been around since the ENIAC.

If you love the modulo operator you can:

counter++;
counter %= 3;

but your counter will count 0,1,2 instead of 1,2,3. It matters not much, because you can use any set of numbers in the switch/case.