Go Down

Topic: Help me correct this please (Read 765 times) previous topic - next topic


May 02, 2012, 08:08 pm Last Edit: May 02, 2012, 08:18 pm by freak174 Reason: 1
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).

Code: [Select]

#define AntalInstr 3

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

Void loop:
Code: [Select]

 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".
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.


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 :P

The switch buttons works good.


"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.


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.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up