Help me correct this please

Hello dear members,

Could some1 see whats wrong with my code?
It worked but at a suddenly it stopped working.

This works with only 2 choices, when I make it 3 it is stuck at the third choice (146).

Global:

#define AntalInstr 3

int InstrVal[AntalInstr] =  {8,9,10};
int Kanal[AntalInstr]    =  {144, 145,146};
int InstrState[AntalInstr] =  {LOW, LOW, LOW};

Void loop:

  for(int i = 0; i < AntalInstr; i++){  
    int buttonState = digitalRead(InstrVal[i]);
  
   if(InstrState[i] != buttonState){
     if(buttonState == HIGH){
     ValdKanal = Kanal[i];
     }
     InstrState[i] = !InstrState[i];
   }      
  }

I'm surprised that even compiles. Change "#define AntalInstr 2" to "#define AntalInstr 3".

Oh Im sry, I had 2 in the code but changed em manually in the thread hehe just forgot that one.
However, it does compile and it worked once or twice, but dunno what happened after :stuck_out_tongue:

The switch buttons works good.

bump

Post your code.

The code posted seems syntactically correct. Indentation (readablility) can be optimized by using CTRL-T before posting!

Post your complete code as the error does not seem to be in the part you post.