Why is "if pinC.0 = 1..." needed when high C.0 or sound C.0,(...) is acceptable?

RadioBob

New Member
Why is "if pinC.0 = 1..." needed when high C.0 or sound C.0,(...) is acceptable?

Is there any logic behind the need for "pin" in front of the port.number format that is used in "if pinC.0 = 1 ..." when it is not needed for statements like "high C.0" or "sound c.0,(...)"?

The logic would appear to be more consistent if the "pin" was not needed (although both could be acceptable for backward compatibility). Am I missing some other subtlety?
 

SAborn

Senior Member
It all depends if you are talking the pin being an input or an output,

PinC.1 is for the pin as a input.

C.1 is the pin as an output.

Its rather simple is it not?
 

geoff07

Senior Member
I imagine that the person that wrote the code to parse the statement felt that was more efficient or less ambiguous. However, if you use symbol definitions to add clarity to your code you only have to code each once in the symbol declarations at the top, and then you can use meaningful names.
 

g6ejd

Senior Member
Noting these devices were made for the educational market where clarity of learning is paramount, then when they move on in their learning, they can drop the 'pin' :)
 

Technical

Technical Support
Staff member
They are two completely different things - watch the way they colour code when typed.

C.0 is a constant, with the value of the pin number. C.0 happens to have the value 8, C.1 the value 9 etc.

pinC.0 is a variable, a bit variable that can contain the number '0' or '1'


You can't do a if...then type statement on a constant, to the compiler it doesn't make any sense, as you are saying
if C.0 = 1 then...
means
if 8 = 1 then...
so will never become true.

So if...then requires the name of a variable, something that can change value (in the case of pinC.0 the value 0 or 1)

So you use a pin name constant on a command to select the pin of choice, both input or output commands such as serout, serin, pulsout, pulsin etc.
And the variable name when you need a variable, within if...then and similar (select case, let= equations etc.).
 
Last edited:

Haku

Senior Member
I've been wondering this too, sometimes it's been a little annoying having to deal with both types. For instance, these will have the same result:

high c.0

pinc.0=1

It means you can't have a single defined symbol for example called TactileButton which will work wth "input TactileButton" and "if TactileButton=1"
 

Technical

Technical Support
Staff member
We realise it is a little confusing to start with, but think about the difference, 'high c.0' is an instruction on a pin constant, whilst 'pinC.0 = 1' is allocating a value to a variable.
 

nick12ab

Senior Member
It means you can't have a single defined symbol for example called TactileButton which will work wth "input TactileButton" and "if TactileButton=1"
As a compromise, however, you can use slightly different constant names for each so C.0 could be tactilebutton and pinC.0 could be pinTactileButton or TactileButtonPin.
 

Haku

Senior Member
With the Picaxe Programming Editor being a BASIC interpreter, if you used C.0 for all occasions surely the PE could be coded to interpret when C.0 was needed and pinC.0 was needed and so compiled the resulting code with the necessary qualifier?
It already warns you when you don't use the right qualifier so it seems like a small step for the PE to substitute the right qualifier when it sees you're referring to an IO pin.
 

RadioBob

New Member
Thank you everyone for your discussion. I have responded to each reply with my thoughts. While I do not expect things to change, I hope the discussion is useful to some. For me, it helped finding out that pinC.0 was a VARIABLE -- I had thought it was just the input form of the value for the leg C.0. I also did not realize that the IF statement does not accept a logical value, only a logical expression that must involve a variable.

Bob Shaw.


SAborn – No, it is NOT simple. It is NOT obvious. C.0 should be recognized by its context to be input or output. How can the value of a single pin have other than a 0 or 1 value unless perhaps used as an analog input?

Geoff07 – No. Even using symbol statements, you HAVE to use separate declaratives to define pinC.0 and C.0 separately. A professional writing the interpreter should not have had any difficulty in parsing with just C.0.

G6ejd – For learning purposes, the two forms are MORE confusing as well as unnecessary. With more learning, you CANNOT drop the pin with this compiler.

Technical – Yes, C.0 IS a constant, and refers to a specific hardware leg, which can have a value of 0 or 1. pinC.0 does appear to be a variable, as it can take on any byte value, but logically does not refer to the specific hardware leg. There should be no confusion in an if statement with something like if 5=7… -- it should logically be an if statement that is NOT TRUE. In fact, it should be the literal reference to 5 is not equal to the leteral reference of 7. The if statement seems to REQUIRE a variable in a logical expression which is probably the original necessity for pinC.0. If the if statement took as its argument a logical , then a statement like if 1 then … should be possible. So the current if statement cannot accept a logical value, only a logical expression which further must refer to a variable. Isn’t this rather confusing!

Haku – I agree with your comments.

Technical – I disagree. “pinC.0 = 1” should be thought of as a logical expression. There does not appear to be any reason that a VARIABLE pinC.0 refers to a specific leg, especially as it can be assigned not just a value of 1, but any byte value. (I didn’t check if it can in fact be any word value as well).

Nick12ab – This is just agreeing with the concept that C.0 is different than pinC.0.

Haku – Again, I agree with your comment. If the BASIC interpreter/compiler accepted C.0 and pinC.0 equally and inferred if being used as input or output, and pinC.0 was accepted as C.0 as input (legacy), I believe the PicAXE BASIC language would be improved (less confusing).
 

hippy

Technical Support
Staff member
With the Picaxe Programming Editor being a BASIC interpreter, if you used C.0 for all occasions surely the PE could be coded to interpret when C.0 was needed and pinC.0 was needed and so compiled the resulting code with the necessary qualifier?
It's not quite that simple, for example, what would the following do ...

b0 = C.0
b1 = pinC.0

For the first, how would the compiler know you wanted to put the pin identifier into b0 or the value which is present on that pin input ?

And what about ...

b0 = C.0
High b0

Which is not the same as ...

b0 = pinC.0
High b0
 

SAborn

Senior Member
I dont follow your argument about why a pin variable should except any value of a number....for what reason?
If its used as a digital input then there is only 2 states, 1 or 0, if its used as a analog input than that is defined with readadc.

It would seem you want a interpreter to workout what you are thinking, and not what you are programming in code.
It is simple with you must use the right tools for the right job, same with any job, or any program.
 

geoff07

Senior Member
I'm sure it is true that it could have been parsed in such a way that a single form would do service in both ways. My point was that they didn't do that, for whatever reason, and the cost of not doing so is very small.

There are many changes that I would like to do to the Picaxe Basic language, such as adding functions (i.e. variable names that are evaluated by user subprograms) or parameter passing, or arrays, but then it would be Algol or some recent variant, not Basic! And it probably wouldn't fit on the limited PIC architecture anyway. And then there is the question of floating-point.

Even without these things, it is a pretty awesome form of Basic.
 
Top