pinC.x vs C.x

KeithRB

Senior Member
Is there any rhyme or reason as to when to use which of the above?

I am trying to use symbols but sometimes I get just a number instead of the actual high or low value of the pin.
 

srnet

Senior Member
When using a pin as an input such as a switch on pin b.0 you would use;

symbol switch = pinb.0

If switch = 0 then
gosub doaction
end if

If you had an LED on pin b.1 as an output you would use the form;


symbol PXLED = b.1

high b.1
 

KeithRB

Senior Member
Doesn't help my symbol problem! (Which is why I asked for "smart" symbols in the wish list thread.)
 

nick12ab

Senior Member
Simply:

A.x, B.x, C.x and D.x are all constants and if you were to set a variable to one (e.g. b0 = A.2), in the simulator you'd get some constant, in this case it's 18 on the 28X2. The PICAXE firmware is told through this constant which pin to use, and is why 'high 0' gets accepted. It's like there's an invisible list of symbol definitions with the values in (symbol A.2 = 18 etc). pinA.x, pinB.x, pinC.x and pinD.x represent variables that hold the state of the pin when accessed or change the state of the pin when written.

With symbols, so that you know which one is the pinY.x variable and which is the Y.x variable, you could call the pin variant pinLedPin and the non-pin variant LedPin or whatever. Also, the constants and variables get coloured appropriately too and in the PICAXE evil genius book, different symbols are categorized and the Y.x symbols are filed under 'constants' whereas the pinY.x symbols are filed under variables.
 

Technical

Technical Support
Staff member
As pinC.x is a variable and C.x is a constant, the only time you use pinC.x is when you need to check a changing variable value (is it 0 or1) - e.g. if...then and let... expressions.
 

geoff07

Senior Member
As the use is clear from the context, could not a smart compiler figure this out? It seems to raise a disproportionate number of questions.
 

hippy

Ex-Staff (retired)
As the use is clear from the context, could not a smart compiler figure this out?
No, and it's not always clear from context whether pinC.0 or C.0 is meant if only one or the other were allowed by the compiler.

The compiler can no better guess which is intended than you or I can when it sees ...

Let b0 = C.0

I recall writing some further explanation in a previous post somewhere.

The best option for dealing with both pin names and contents of pin names is to define two symbols, for example ...

Symbol BTN = C.0 : Symbol BTN_PIN = pinC.0

And possibly also add the direction control bit as well ...

Symbol BTN = C.0 : Symbol BTN_PIN = pinC.0 : Symbol BTN_DIR = dirC.0
 

inglewoodpete

Senior Member
Simulation to show the difference....

Perhaps a simple example that you can run in the simulator would help here.

  • Paste the attached code into the Programming Editor.
  • Click the 'Simulate' button.
  • On the 'Simulation' dialogue box that opens, click on the 'Expand' button [>>] to show the contents of the variables.
  • Observe the values showing for variables b0 and b1
  • Click on the input pad for pin C.0 on the simulated chip
  • Once again, observe the values showing for variables b0 and b1

The value in b0 shows constantly as '8': the firmware 'address' of pin C.0. The value in b0 will change from 0 to 1 according the the digital condition applied to the input.

Code:
#PICAXE 20M2
Here: b0 = C.0
      b1 = pinC.0
      GoTo Here
 

KeithRB

Senior Member
Thanks for the explanation everybody, as a C programmer, I understand the difference between a pointer and what it points to!

'Or else it doesn't, you know. The name of the song is called 'Haddocks' Eyes.''

'Oh, that's the name of the song, is it?' Alice said, trying to feel interested.

'No, you don't understand,' the Knight said, looking a little vexed. 'That's what the name
is called. The name really is 'The Aged, Aged Man.''

'Then I ought to have said 'That's what the song is called'?' Alice corrected herself.

'No you oughtn't: that's another thing. The song is called 'Ways and Means' but that's only
what it's called, you know!'

'Well, what is the song then?' said Alice, who was by this time completely bewildered.

'I was coming to that,' the Knight said. 'The song really is 'A-sitting On a Gate': and the
tune's my own invention.'
 
Top