PIN declaration?

FergusonRW

New Member
What is the equivalent of a "PBasic" PIN declaration? It appears that I need to use "outpin1" to set pin1 to High/Low in my code. For readability and flexibility I would like to use a pin name instead of "outpin1". Is there a way to use a name instead of "outpin1" when pin 1 is to be set high/low depending on the contents of another bit variable?

For example:
SYMBOL Pin_GreenLED = outpin1 ' Use a symbol name in place of "outpin1".
~
~
Pin_GreenLED = my_bit0 ' output pin number 1 is assigned high/low depending on variable
~
~

Thank you
 

MPep

Senior Member
Most people will tell you to read the manual. Only obvious really!!

But.... to get you started:
The short answer is to use the symbol statement.

Code:
symbol GreenLED = 1
symbol GreenSwitch = 1
Both can be used in the same code, depending on which PICAXE you use, because the LED version would (most likely) be used with an ouptut type statement:
eg
Code:
 high GreenLED
.

The Switch statement would be used something like this:
Code:
 if GreenSwitch = 1 then ....
.

When used in this way the compiler 'knows' that an input is required, and the assigned name is GreenSwitch.

Hope this helps.

Mark.
 

westaust55

Moderator
With IF...THEN staements:

When using inputs the input variable (pin1, pin2 etc) must be used
(not the actual pin name 1, 2 etc.)
That is; the line must read ‘if pin1 = 1 then...’, not ‘if 1 = 1 then...’

"pin1", "pin2", etc are effectively already symbolic names for the input pins.
 
Last edited:

FergusonRW

New Member
Still looking for equivalent to PBasic logic

The following code is from a BS2 program and is included to highlight how the "PIN" assignment is used in PBasic.

' {$PBASIC 2.5}
RedLED PIN 0 ' no PICAXE equivalent

IsOn CON 1 ' same as SYMBOL IsOn = 1
IsOff CON 0 ' same as SYMBOL IsOff = 0

Main:
DO
RedLED = IsOn ' same as OUTPIN0 = IsOn
PAUSE 1000
RedLED = IsOff ' same as OUTPIN0 = IsOff
PAUSE 1000
LOOP

I have read quite a bit of the documentation and am beginning to think that PICAXE programs require the programmer to translate pin numbers into pin function. And that a change to the pin connections will require a careful search through the program for all the references to the pins that have been changed.

It may sound like I'm complaining (hope not), I am really checking to see if I have overlooked something in the documentation.

Thanks
 
Top