My program summary is I want to set some "ifs" in my program and I have 9 inputs and 3 outputs(the count of I/Os can change) but I have trouble in my program and there is the code:
char cntlstate2; //I set character variables there
char cntlstate3;
char mc11;
char mc12;
char mc31;
char mc32;
char mc21;
char mc22;
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT); //I setup pin I want to take action there
pinMode(3, INPUT);
pinMode(4,INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
/*they are namespace of microswiches mcs are microswiches
* and cntlstates are for tasks from user
*/
cntlstate1 = digitalRead(8); //I set data for variables there
cntlstate2 = digitalRead(9);
cntlstate3 = digitalRead(10);
mc11 = digitalRead(2);
mc12 = digitalRead(3);
mc21 = digitalRead(4);
mc22 = digitalRead(5);
mc31 = digitalRead(6);
mc32 = digitalRead(7);
//this statement is for M1
if (mc22 == HIGH && mc32 == HIGH && cntlstate1 == HIGH) { //I put the maincode there
digitalWrite(11, HIGH);
} else {
digitalWrite(11, LOW);
}
//this statment is for M2
if (mc11 == HIGH && mc32 == HIGH && cntlstate2 == HIGH) {
digitalWrite(0, HIGH);
} else {
digitalWrite(0, LOW);
}
//this statment is for M3
if (mc12 == HIGH && cntlstate3 == HIGH) {
digitalWrite(1, HIGH);
} else {
digitalWrite(1,LOW);
}
}
and the trouble is the function in loops do not doing anything
You might also want to check your 3 while statements and ask yourself if you enter in one of those (if the condition in the while (condition) is true) how are you going to exit that while. (Hint - at the moment seems you'll be stuck in that loop forever)
arygholo:
I know but I don,t know why this get like that anyway the smiley face is 8 in program.
arygholo:
elvenstof you mean I write code like this:
if (cntlstate1 == HIGH) {
if (mc22 == HIGH && mc32 == HIGH) {
digitalWrite(11, HIGH);
}
?
thank for repling:D
In :
While (cntlstate1 == HIGH) {
if (mc22 == HIGH && mc32 == HIGH) {
digitalWrite(11, HIGH);
}
Te program will check if cntstate1 == high, if that is true it will check if mc22 and mc23 are true. If that is true it will set pin 11 to high.
But after that the program will check if cntlstate1 == high again and if it is it will check mc22 and mc23 again and set pin 11 to high again.
So unless pin 11 going high makes cntlstate1 (pin 8 I guess) become low. The code will stay in an infinite loop.
What do you want your code to do?