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?