AND

69-cat

Member
Is there a way to have more than 2 inputs to control an output? If I add a 3rd, I get errors with the simulator....

Dave

;2 input AND gate
main:
if pinC.1 = 1 and pinC.2 = 1 then high c.4
else low c.4
endif
goto main
 

Flenser

Senior Member
69-cat,

From the PICAXE manual2 the IF statement only allows 1 or 2 tests so no, you can't specify 3:
Syntax:
IF variable ?? value {AND/OR variable ?? value ...} THEN
{code}
ELSEIF variable ?? value {AND/OR variable ?? value ...} THEN

Seeing as the pinC.N values are either 1 or 0 a workaround for you is this:
Code:
bit1 = pinc.1 and pinc.2 and pinc.3
if bit1 = 1 then high c.4
else low c.4
endif
 

westaust55

Moderator
While the IF...THEN statement uses two "tests" as an example, it does not categorically state there cannot be more.

Using three tests in the IF . . . THEN statement is working for me in the PE6 simulator
Three-Input Test.png
Both the code by Flenser and that I tried happen to use 21 bytes each.
 
Last edited:

Flenser

Senior Member
westaust55,

You are correct. I didn't look at the IF statement syntax carefully enough.

{AND/OR variable ?? value ...}
- That "..." at the end usually means that you can repeat the clause more times.
 

Aries

New Member
It was a "syntax" error,
Just for the record, a syntax error is nothing to do with the simulator - it is a problem with your code and the compiler (and I would put money on it being the code and not the compiler)
 
Top