- Name:
-
if pin
- Syntax:
-
Single line options:
IF pin XX ?? value {AND/OR variable ?? value ...} THEN label
IF pin XX ?? value {AND/OR variable ?? value ...} THEN GOTO label
IF pin XX ?? value {AND/OR variable ?? value ...} THEN GOSUB label
IF pin XX ?? value {AND/OR variable ?? value ...} THEN EXIT
pin XX - the number of the pin to check.
Value - is a variable/constant (usually either 0 or 1).
?? - comparison operator can be any of the following conditions:
| |
= |
equal to |
| |
is |
equal to |
| |
<> |
not equal to |
| |
!= |
not equal to |
| |
> |
greater than |
| |
< |
less than |
Multiple line/block structured options:
IF pin XX ?? value {AND/OR pin XX ?? value ...} THEN
{code}
ELSEIF pin XX ?? value {AND/OR pin XX ?? value ...} THEN
{code}
ELSE
{code}
ENDIF
pin XX - the number of the pin to check.
Value - is a variable/constant (usually either 0 or 1).
?? - comparison operator can be any of the following conditions:
| |
= |
equal to |
| |
is |
equal to |
| |
<> |
not equal to |
| |
!= |
not equal to |
| |
> |
greater than |
| |
< |
less than |
- Description:
-
When using inputs the input variable (pin1, pin2 etc) must be used (not the actual pin name 1, 2 etc.) i.e. the line must read 'if pin1 = 1 then...', not 'if 1 = 1 then...'
Some PICAXE parts have additional inputs on porta and portc. To read the state of PORTA and PORTC pins on the older 28X/X1 parts, they keyword PORTA or PORTC is inserted after IF to redirect the whole line to the desired port. For newer parts use the direct PORT.PIN notation instead e.g. if pinC.1 = 1 then....
When using PORTA or PORTC keywords, it is possible to use AND and OR within the command, but all pins tested will be on the same port, it is not possible to mix ports within one line.
The if...then command only checks an input at the time the command is processed. Therefore it is normal to put the if...then command within a program loop that regularly scans the input. For details on how to permanently scan for an input condition using interrupts see the 'setint' command.
To read the whole input port at once the variable 'pins' can be used if pins = %10101010 then gosub label. To read the whole input port and mask individual inputs (e.g. 6 and 7) let b1 = pins & %11000000, if b1 = %11000000 then gosub label.
The words is (=), on (1) and off (0) can also be used with younger students.