2 or more inputs high to switch an output

I'm having great difficulty adapting to Arduino from basic Stamp programming, not that I'm am very competent with the Stamp system.

My current problem is trying to get two inputs to switch an output.

eg. IF ((input1 = high) and (input2 = high)) THEN HIGH output9

eg. IF ((Man_Stop =0) OR ( Overflow = 0 )) THEN LOW 10

I just can't figure Arduino referencing at this stage

eg. IF ((input1 = high) and (input2 = high)) THEN HIGH output9

eg. IF ((Man_Stop =0) OR ( Overflow = 0 )) THEN LOW 10

if (digitalRead(input1)==HIGH && digitalRead(input2)==HIGH){
  digitalWrite( output9, HIGH );
}
if (Man_Stop || Overflow){
  digitalWrite( output10, LOW );
}

:)

if (Man_Stop == 0 || Overflow == 0){
  digitalWrite( output10, LOW );
}

:) :)

Oh!

Note to self: Do not try to code when the clock is 05:something.

Good night! ::slight_smile:

Hi,

there is stilkl a problem, because the output 9 will be switched on but never off. Therefore change the code as follows:

if (digitalRead(input1)==HIGH && digitalRead(input2)==HIGH){ digitalWrite( output9, HIGH ); } else digitalWrite(output9,LOW);

Good luck

How about:

digitalWrite( digitalRead(input1) && digitalRead(input2) );

Depending on who is doing the reading it could be argued that this is not as clear as an if statement with tests against the boolean constants. Functionally speaking either one is fine, but I prefer to not test against true/false or high/low whenever it can be avoided.

Depending on who is doing the reading it could be argued that this is not as clear as an if statement with tests against the boolean constants. Functionally speaking either one is fine, but I prefer to not test against true/false or high/low whenever it can be avoided.

I have the same preference, but for code that is published here, I think the explicit if statement is easier for inexperienced programmers to comprehend

digitalWrite( digitalRead(input1) && digitalRead(input2) );

How does digitalWrite function know which pin to write to?

Lefty

Lefty, I think DaveK intended: digitalWrite( output9, digitalRead(input1) && digitalRead(input2) );

and I think he would agree that the 'if' version is easer on the eye

Lefty, I think DaveK intended: digitalWrite( output9, digitalRead(input1) && digitalRead(input2) );

heh, yeah, sorry, was still working on the first cup of coffee when I wrote that. I've had plenty now [smiley=cheesy.gif]

In my own code I'd probably do it on one line. For a beginner or for someone who isn't a primarily a programmer the more verbose version would probably be easier to understand and maintain, and therefore more appropriate.

IMO, until space or performance become an issue it 'should' be whatever the creator feels is the most natural way to express it.

It ‘should’ be whatever the creator feels is the most natural way to express it.

There is usually little space or performance disadvantage in using verbose expression – the compilers optimizer will often product just as efficient runtime code