How do I use an "or" statement in arduino?


i need make "if" statement read multiple inputs, , if 1 of them triggered, run statement. how this?


context:
code: [select]
void loop(){
 do
 {
   digitalwrite(led1, low);
   digitalwrite(led2, low);
   sw1 = digitalread(s1);
   sw2 = digitalread(s2);
   sw3 = digitalread(s3);
   sw4 = digitalread(s4);
 }
 while ( sw1 == high );
 
 while ( true )
 {
   val1 = digitalread(r1);
   val2 = digitalread(r2);
   val3 = digitalread(r3);
   val4 = digitalread(r4);
   if (val1 == high) {      <--- or statement needs go here , read val2, val3, , val4 val1
         digitalwrite(led1, high);
         delay(10);
         digitalwrite(led1, low);
         if (val1 == high) { <---- same here!
           digitalwrite(led2, high);
           delay(10);
           digitalwrite(led2, low);
         }
   }

 }
}
   

code: [select]
if (value==1 || value==2) {
 // something
}


two pipe symbols mean "or" (single pipe symbol bitwise or, iirc)...

so - in case:

code: [select]
if (val1 == high || val2 == high || val3 == high || val4 == high) {
 // stuff
}


:)


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > How do I use an "or" statement in arduino?


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums