Constants list reports incorrect pin numbers

120ThingsIn20Years

Senior Member
Can anyone tell me why

symbol Motor = c.0

reports under the Constants list

Motor = 8

It's as if the pin numbers are back to front.



symbol Motor = c.1

reports

Motor = 9

Are these numbers (8 and 9) not pin numbers?

In not, can anyone tell me what they are?
 

MPep

Senior Member
They are constants internal to the compiler. Don't worry about it. :) The code will work according to what you want to have happen on the correct pins.
 

120ThingsIn20Years

Senior Member
Oh yeah sorry

14M2

It doesn't really matter, but I just don't like not understanding stuff :)

It tends to lead to trouble down the line, and it's just that it was different from what I was expecting.

I figured if it was going to display a value other than Motor = PinC.0, that it should reflect the actual pin number or something.

Usually when something is reported back to the user, it has some value to the user.

I think there are only 7 ADC pins on the 14M2
 

120ThingsIn20Years

Senior Member
Did you try:

symbol Motor = 8

...

symbol Motor = 9

...

?
This isnt me trying to assign a value other than to name a Pin with an english name ie Motor = C.0, and the thing I thought was strange was that in the variables list on the right of screen, it lists

Motor = 8 even though it's actually on pin C.0 or pin 7 depending on how you look at it.

But according to MPep,

They are constants internal to the compiler. Don't worry about it. :) The code will work according to what you want to have happen on the correct pins.
That's good enough for me, but I still think it's a little strange for the variables list to tell me about it.

I'm confused enough as it is in life without having meaningless (to me) numbers thrown into the mix :)
 

Technical

Technical Support
Staff member
symbol Motor = c.0
symbol Motor = 8

are both exactly the same, as the compiler already has a 'hidden'

symbol c.0 = 8

so as far as the compiler is concerned it is

symbol c.0 = 8
symbol Motor = c.0

hence motor = 8
 

120ThingsIn20Years

Senior Member
MPep, I have no idea. I just looked at it again :)

I find code I haven't written soooo hard to read. Actually, if I'm honest, I find code I have written hard to read as well :)

Thanks Technical and westaust55
 

Paix

Senior Member
I find code I haven't written soooo hard to read. Actually, if I'm honest, I find code I have written hard to read as well

Yes, but you have forgotten that there was a time when reading was difficult too. Patience and persistence. Practice makes perfect etc. :)
 

120ThingsIn20Years

Senior Member
So now I find myself stuck again on a similar topic...

I have this ...

Code:
'Pins ----------------------------------------------------------


	Symbol ReportFeedsTodayLED = c.1


	Symbol FeedsPerDayLED = B.0
	
	Symbol FeedSizeLED = B.2
And I want to do...

Let LEDVariable = ReportFeedsTodayLED

and then later

Let LEDVariable = FeedsPerDayLED

etc.


So I can reuse the code that plays with LEDVariable without having to have 3 identical versions of it (the code flashes out the value of some trimpots on a LED sitting next to the pots - 3 trim pots 3 LEDs)

But the line ...

Let LEDVariable = ReportFeedsTodayLED

Stores "9", when I really want it to store "C.1" in LEDVariable

Is there a way around this, or do I just have to hard code each situation rather than making it dynamic?
 

MartinM57

Moderator
But c.1 is equal to 9, so what's the problem? What's the subsequent code that tries to use LEDVariable?

You can't store "C.1" in a PICAXE byte or word variable anyway - "C.1" is a 3-character string (as you have written it) and PICAXE Basic can't handle simple multi-character string assignments to variables
 

120ThingsIn20Years

Senior Member
I have a LED flashing out the Value of a trimpot as I'm changing it to give feedback to the user.

But I have 4 trimpots, and 4 LEDs so I want to reuse the feedback code.

What I tried to do was pass the variables holding the pot value and LED pin to the report gosub, so I could reuse the code.

This is what I have now, but I want to reuse the code for reporting other than "TodaysFeeds", and report the values on other than "ReportFeedsTodayLED"

Code:
ReportTodaysFeeds:


	pause LongReportPause 'pause for the desired time between each report
	
	Do
		if TodaysFeeds = 0 then 
			GoSub FlashZero
		endif
		Counter2 = TodaysFeeds/10                 'isolate tens
		for Counter1 =1 to Counter2           'flash tens
			if Counter2=0 then 
				Gosub ReportTodaysFeedsRemainder 
			end if
			high ReportFeedsTodayLED
			pause 800
			low ReportFeedsTodayLED                    'LED off
			pause 40
			high ReportFeedsTodayLED
			pause 40
			low ReportFeedsTodayLED
			Pause 780		
		next Counter1
	loop
end
'----------------------------------------------------------
	ReportTodaysFeedsRemainder:
		Counter2 =TodaysFeeds//10               'isolate remainder 
		for Counter1 =1 to Counter2           'flash units
			if Counter2=0 then 
				gosub ReportTodaysFeedsFlashZero
			end if
			high ReportFeedsTodayLED
			pause 200
			low ReportFeedsTodayLED
			pause 200
		next Counter1
	return
	end
'----------------------------------------------------------
	ReportTodaysFeedsFlashZero:
		high ReportFeedsTodayLED
		pause 40
		low ReportFeedsTodayLED
	Return
	end
}
 

120ThingsIn20Years

Senior Member
This is on a 14M2, and I have a stack of free space, so I can just do it all longhand and duplicate it 4 times, but I'm trying to learn for the sake of learning, so wanted to do it right.

But if there is no way of passing a pin to a new variable, then I'll just duplicate the code 4 times
 

hippy

Ex-Staff (retired)
But if there is no way of passing a pin to a new variable, then I'll just duplicate the code 4 times
There is, it's really just that you are looking too deeply at how things work behind the scenes rather than accepting things at face value.

For example, connect two LED+R up to B.0 and B.2 then try this ...

Code:
#Picaxe 14M2

Symbol LED_A    = B.0
Symbol LED_B    = B.2

Symbol ledToUse = b0
Symbol counter  = b1

Do
  ledToUse = LED_A
  Gosub FlashLed
  ledToUse = LED_B
  Gosub FlashLed
Loop

FlashLed:
  For counter = 1 To 5
    High ledToUse
    Pause 250
    Low ledToUse
    Pause 250
  Next
  Return
 

westaust55

Moderator
@120TI20Y,
As per the information I pointed you to back in post 10, the pin identifiers such as B.0 and C.1, etc are pre-defined aliases for constants within the Programming Editor.
As per that information, B.0 is an alternate name for the value 0, B.1 is 1 and as MartinM57 states above, C.1 = 9.
Hence for C.1 any variable to which you assign the pin identifier will contain the numerical constant value.
In your case the alias is C.1 so the constant is 9 that is passes to the variable in your LET statement.

Remember that a variable only holds a number, not a text string.
The number might however be the ASCII code for a Single character such as "A"
 
Last edited:

120ThingsIn20Years

Senior Member
There is, it's really just that you are looking too deeply at how things work behind the scenes rather than accepting things at face value.

For example, connect two LED+R up to B.0 and B.2 then try this ...

Code:
#Picaxe 14M2

Symbol LED_A    = B.0
Symbol LED_B    = B.2

Symbol ledToUse = b0
Symbol counter  = b1

Do
  ledToUse = LED_A
  Gosub FlashLed
  ledToUse = LED_B
  Gosub FlashLed
Loop

FlashLed:
  For counter = 1 To 5
    High ledToUse
    Pause 250
    Low ledToUse
    Pause 250
  Next
  Return
Hmmm. I think that's what I tried originally.

Perhaps the reported error was caused by some other bug. I'm re-writing the entire thing, so there's a far chance of typos. I'll revisit it in the morning and have another look with a clear head.

I just tested this, and it worked just fine, so the error must be somewhere else :(

#Picaxe 14M2

Symbol LED_A = B.0
Symbol LED_B = B.2


Symbol ledToUse = b0
Symbol counter = b1
symbol test1 = b2
symbol test2 = b3
symbol testnumber = b4


let test1 = 3
let test2 = 6


Do
ledToUse = LED_A
TestNumber = test1
Gosub FlashLed
ledToUse = LED_B
testnumber = test2
Gosub FlashLed
Loop


FlashLed:
For counter = 1 To testnumber
High ledToUse
Pause 250
Low ledToUse
Pause 250
Next
Return
But at least I've narrowed it down to something I dont suspect :)
 

hippy

Ex-Staff (retired)
Perhaps the reported error was caused by some other bug.
Was there actually a "reported error" ? It seemed you were more confused/concerned by the value one of the constants was being given rather than having an actual error which was stopping a Syntax Check being successful.
 

120ThingsIn20Years

Senior Member
oh, no sorry there wasnt. Just an error in the way my stuff was working. I got that mixed up with a different problem :)

But I think the problem was actually a missing exit from a do loop. The program was running into the rest of the loop and just happened to be flashing out 9.

So your solution (similar to my first attempt) did actually work once I got the bug out.

Once again the problem is that, because I'm a beginner, I cant tell if this is a problem with what I'm asking the chip to do, or if it's a problem with how I'm going about asking it.

The business with the 9 was because I couldn't find my problem, and thought it might be to do with that because it just happened to be flashing out that digit.

The do loops are very new to me, so I'm still struggling a bit with the mind shift in using them.

But thanks to your setting me straight, I knew it must be a program error, so renewed my efforts and found the problem.
 
Top