okey, i know that the tittle sucks. but i have the following problem.
in my sketc, i want an action to be done, both , when a specific serial input arrives, or/and a hardware input is given (button press).
my code is as follows ::
int LU=0;
int LD=0;
int RU=0;
int RD=0;
int defrost=0;
int Rfog=0;
void setup() {
Serial.begin(9600);
Serial.setTimeout(50);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
pinMode(A4, INPUT_PULLUP);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(13,HIGH) ;
digitalWrite(12,HIGH) ;
digitalWrite(11,HIGH) ;
}
void loop() {
if (Serial.available()>0 )
{
int LU = Serial.parseInt();
int LD = Serial.parseInt();
int RU = Serial.parseInt();
int RD = Serial.parseInt();
int defrost = Serial.parseInt();
int Rfog= Serial.parseInt();
if ( (digitalRead(A1)==LOW)||(LU==1) ) {digitalWrite(4,HIGH);}
else{digitalWrite(4,LOW);}
if ( (digitalRead(A2)==LOW)||(LD==1) ){digitalWrite(5,HIGH);}
else{digitalWrite(5,LOW);}
if ( (digitalRead(A3)==LOW)||(RU==1) ){digitalWrite(2,HIGH);}
else{digitalWrite(2,LOW);}
if ( (digitalRead(A4)==LOW)||(RD==1) ) {digitalWrite(3,HIGH);}
else{digitalWrite(3,LOW);}
Serial.print(LU);
Serial.print(LD);
Serial.print(RU);
Serial.print(RD);
Serial.print(defrost);
Serial.println(Rfog);
}
/* THIS HERE IS MY TRY, TO MAKE IT WORK EVEN WHEN NO SERIAL ARRIVES.
if ( (digitalRead(A1)==LOW)||(LU==1) ) {digitalWrite(4,HIGH);}
else{digitalWrite(4,LOW);}
if ( (digitalRead(A2)==LOW)||(LD==1) ){digitalWrite(5,HIGH);}
else{digitalWrite(5,LOW);}
if ( (digitalRead(A3)==LOW)||(RU==1) ){digitalWrite(2,HIGH);}
else{digitalWrite(2,LOW);}
if ( (digitalRead(A4)==LOW)||(RD==1) ) {digitalWrite(3,HIGH);}
else{digitalWrite(3,LOW);}
*/
}
i dont know if there is something that i dont understand, BUT: if the arduino is connected to pc, and serial comes all the time, then it works both with buttton, and with serial. but if its not connected to pc, and no serial arrives, then nothing happens even when i press the button.
the second paragraph (commented out), is my try to make it work withg no serial input, but if i add that paragraph, then nothing works at all... anyone can tell me what i am missing??? thanks!!