If...then symbol definition

tracecom

Senior Member
The following code runs, but in order to make it compile, I had to change the symbol definition for p_button from C.3 to pinC.3. I presume that is because pin references in if...then statements must be in that format. Is there a workaround for that?

Thanks.
Code:
[color=Navy]#picaxe [/color][color=Black]08m2 [/color][color=Green]'Identify the PICAXE being used as an 08M2.[/color]
[color=Navy]#no_data [/color][color=Green]'Prevents data from being downloaded to PICAXE.
   [/color][color=Blue]symbol g_led [/color][color=DarkCyan]= [/color][color=Blue]C.2
   symbol y_led [/color][color=DarkCyan]= [/color][color=Blue]C.1
   symbol r_led [/color][color=DarkCyan]= [/color][color=Blue]C.0
   symbol light [/color][color=DarkCyan]= [/color][color=Navy]1000
   [/color][color=Blue]symbol [/color][color=Purple]p_button [/color][color=DarkCyan]= [/color][color=Purple]pinC.3
   [/color][color=Black]main: [/color][color=Green]'Start 'main' program.
      [/color][color=Blue]if [/color][color=Purple]p_button [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then
         high g_led
         pause light
         low g_led
      endif
   goto [/color][color=Black]main [/color][color=Green]'Go to 'main' program.[/color]
 

hippy

Technical Support
Staff member
There's no workaround because there is nothing to work around; "C.3" is simply a pin identifier, "pinC.3" is a variable which gives the input level status of pin C.3. You need to use "pinC.3" to read the level at the pin.
 

tracecom

Senior Member
There's no workaround because there is nothing to work around; "C.3" is simply a pin identifier, "pinC.3" is a variable which gives the input level status of pin C.3. You need to use "pinC.3" to read the level at the pin.
Thanks.

So, there is no circumstance under which I would need to use the symbol p_button outside an if...then command?
 

westaust55

Moderator
Additional to the information hippy provided, the pin designations such as C.3 are pre-defined constants.
The test in an IF...THEN command must test a variable against a constant or another variable.
Testing a constant against a constant has a low probability of a match ie only if they are both equal.

Outside an IF...THEN command a variable such as pinC.3 could still be used keeping in mind the value for that variable can only ever be 0 or 1.
If might be used as a switch control with for example an XOR command to invert/toggle the state/value of a bit variable or with multiply to get a result of zero or the original value.
 

techElder

Well-known member
An additional point to make in using "p_button" to refer to pinC.3 is that someday you can change the pin that the button is connected to and NOT HAVE TO CHANGE ANYTHING ELSE IN YOUR PROGRAM.

symbol p_button = pinC.3 ... changes to ... pinC.4 WITHOUT HAVING TO CHANGE ANYTHING ELSE IN YOUR PROGRAM. See?
 

lbenson

Senior Member
Try this in the simulator while toggling pinC.3:
Code:
do
  sertxd(#pinC.3," ",#c.3)
  pause 5000
loop
 
Top