Using logic in "if" statements

sushachawal

New Member
Hello,

Does anyone know if PICAXE can resolve "if" statements with logic in them?

e.g:

If pinsB = b12 OR b3 then gosub...

Thanks

Sush
 

sushachawal

New Member
No that's not really what I was going for with the OR statement.

I'm doing an input read form two synchronous decade counters on the eight inputs so one would be:

%00000001

and ten would be:

%10000000 (using an 18M2+ so that the least significant bit of the two digits is the fourth from the bottom on each side)

So I was hoping if I used an OR logic statement so one OR ten would be eleven because:

%00000001 OR %10000000

is %10000001 right?

Sush
 

rossko57

Senior Member
Using your original example, not this
If pinsB = b12 OR b3 then gosub...
but this
If pinsB = b12 OR pinsB = b3 then gosub...

or using your new ezample
If pinsB = %00000001 OR pinsB = %10000000 then ...

You need to take care there are no unexpected bits in your input, or mask for the bits you are interested in.
 

sushachawal

New Member
No, that doesn't work because I basically want something different
when the input is %10000001 but I thought I could generate this using the two values %10000000 and %00000001 but it seems like within the input command I can't so nevermind thanks for your help anyway
 

lbenson

Senior Member
Basically, no. You cannot perform an operation resulting in a new value within an "if" statement--you must do it before.

If I correctly understand your ambiguous statement, what you might want would be "If pinsB = (b12 OR b3) then gosub". But picaxe basic does not support parentheses (perhaps in part because the number of intermediate values would be difficult to calculate for all conditions).

The quickest way to get an answer is to try something in the simulator. In this case, you get this:
Code:
if pinsB = b12 or b3 then
                               ^

Error: Syntax error in this line!
 

oracacle

Senior Member
it would be helpful if we had what code you have to date, if i understand correctly, you are using a decade counter, which will have a fived output for each number (presume 0-9).

it would be helpful if we had a list for all the port values for each number. there maybe other comand that suit your needs better than the if statement.

also i belive you would have to read the port into a variable first (give me syntax error doing if statement strait of pinsb or portb)

trysomething like this:

Code:
let b0 = pinsb
if b0 = %10000001 then
	'do stuff
else if b0 = %00000001 then
	'do stuff
else if b0 = %10000000 then
	'do stuff
end if
 
Top