Pages: [1]   Go Down
Author Topic: Help me correct this please  (Read 483 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 101
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
#define AntalInstr 3

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

Void loop:
Code:

  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];
   }      
  }
« Last Edit: May 02, 2012, 01:18:16 pm by freak174 » Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6613
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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.

Offline Offline
Full Member
***
Karma: 0
Posts: 101
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-razz

The switch buttons works good.

Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 101
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

bump
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26187
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post your code.
Logged

"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.

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13663
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: