Simple prog posted to this forum wont work

eddydde

Member
As a newbie to PICAXE I have located a programme posted to this forum that I would like to use but it does not work.

Posted on 07/09/2005 under the heading 'ADC Voltage display ?'

Here is the programme:


symbol reading = w0
symbol gain = 192
symbol zero = 10

loop:
readadc 0, reading
reading = reading * gain / 100 + zero
sertxd ("Voltage is ",reading/100,".",reading%100,"", 13)
goto loop

Firstly I changed the routine 'loop' to 'loop1' as 'loop' produces the syntax error 'Loop without DO'.

This fixes that syntax error and the programme then is:

symbol reading = w0
symbol gain = 192
symbol zero = 10

loop1:
readadc 0, reading
reading = reading * gain / 100 + zero
sertxd ("Voltage is ",reading/100,".",reading%100,"", 13)
goto loop1

I am getting a syntax error with the sertxd line.

My limited knowledge of PICAXE shows that there should be a '#' in front of 'reading/100' and 'reading%100 so my modified sertxd line now reads:

sertxd ("Voltage is ",#reading/100,".",#reading%100, 13)

I am still getting syntax errors and I don't know why.

I am using an 18X device with a 10k pot connected between GND and +5 with the wiper connected to chips adc 0 input but until I can get rid of the syntax errors I am unable to test it.

Would appreciate some assistance with this sertxd line so I can get the programe to work.


Eddydde
 

elios

Senior Member
cant do maths on sertxd

edit:


symbol reading = w0
symbol reading1 = w1
symbol gain = 192
symbol zero = 10

loop1:
readadc 0, reading
reading = reading * gain / 100 + zero
reading1 = reading / 100
sertxd ("Voltage is ",#reading1,".",reading%100,"", 13,10)
goto loop1

not sure about the reading%100 <- looks like it should be reading//100 perhaps?
 
Last edited:

elios

Senior Member
reading//100 = remainder of (variable / 100)

reading%100 = remainder of (variable * 100)
 
Last edited:

eddydde

Member
Hi elios,

It still does not work.

I tried both #reading%100 and #reading//100 and I still get a syntax error.

If I remove the #reading%100 (#reading//100) altogether from the sertxd string, I get the first digit which is a great start!

eddydde
 

elios

Senior Member
you cannot do maths in the sertxd

move it out so its like the reading1 (reading1 = reading / 100)

i.e reading2 = reading//100

then in the sertxd have #reading2

edit:


symbol reading = w0
symbol reading1 = w1
symbol reading2 = w2
symbol gain = 192
symbol zero = 10

loop1:
readadc 0, reading
reading = reading * gain / 100 + zero
reading1 = reading / 100
reading2 = reading // 100
sertxd ("Voltage is ",#reading1,".",#reading2,"", 13,10)
goto loop1
 

eddydde

Member
Hi elios,

All fixed!

I have modified the code you sent me just a little:

edit:


symbol reading = w0
symbol reading1 = w1
symbol gain = 192
symbol zero = 10

loop1:
readadc 0, reading
reading = reading * gain / 100 + zero
reading1 = reading / 100
reading = reading//100
sertxd ("Voltage is ",#reading1,".",#reading,"", 13,10)
goto loop1

Thank you so much for setting me on the right path.

It would be good if someone (Administrator?) could go to the original post and make some corrections so that another newbie doesn't get caught like I did with incorrect code.

eddydde
 

inglewoodpete

Senior Member
I think the original post has served it's purpose. It was a post of untested code (that was pretty clear to me, anyway).

You (and others through this thresd) have learned a lot as a result. And you've got free help to get your project going.

That's what forums like this one are so good for: not just providing solutions but helping people learn from their and other's mistakes. Life would be pretty boring if everything worked first time.
 

eddydde

Member
Hi inglewoodpete,
Everything you say is correct.
I for one now know that one cannot use math functions in a sertxd line!
At age 68, I have learnt something today about PICAXE code.

Stage 1 of my project works, now to stage 2!

eddydde
 

BeanieBots

Moderator
It would be good if someone (Administrator?) could go to the original post and make some corrections so that another newbie doesn't get caught like I did with incorrect code.
It would also be very useful if when using posted code that you provide a link to the original thread and/or at least credit the original author.

It is not common practice to "corrrect" (by means of editing) somebody elses code but it is the duty of all members to point out any errors within the thread.
(I have not read that particular thread).
 

eddydde

Member
Hi BeanieBots,

I thought that by giving the date and thread title this would have been sufficient if someone wanted to look it up.

Eddydde
 

techElder

Well-known member
Also, Eddydde, you should learn 2 other things common to forums. And it isn't just you, so don't think you're being picked on.

1) When you post program code, "wrap" the code with the start code and stop code macros called "[CODE]" and "[/CODE]". That means to put "[CODE]" before your code, and put "[/CODE]" after your code. Your code will be highlighted and indented like this:
Code:
symbol rentControl = nope
main:
   gosub controlTheRent
goto main
Here's the place on the forum where you can read about all of the macros available with samples on how to use them.

2) Way down at the bottom of the main/start forum page is a place called "Sandbox" where you can try out some of the forum macros and see how they work without anyone looking over your shoulder! ;)
Thanks for finding that errant code! Keep working on it, adding to it and make it yours!
 
Last edited:

westaust55

Moderator
It would also be very useful if when using posted code that you provide a link to the original thread and/or at least credit the original author.

It is not common practice to "corrrect" (by means of editing) somebody elses code but it is the duty of all members to point out any errors within the thread.
(I have not read that particular thread).
Original code from this thread: http://www.picaxeforum.co.uk/showthread.php?t=3179

But as it is now in archives (No 12) no ability for most of us to add another post.
 

eddydde

Member
Thank you TCH, I will do some reading up and hopefully will get it right next time. So much to learn for an oldie newbie, or should that be newbie oldie? :confused:

eddydde
 

BeanieBots

Moderator
Thanks for the link Westy.

@ eddydde, Some people just love looking things up and searching. (no names EC;))
I don't. I'm really lazy and I like people who want free help to put in as much effort as possible so that I don't have to. In fact, I often put in more effort trying to extract the information from the poster than it would take to find the answer and spoon feed it back. I'm not having a dig, just letting you know how lazy I am:)

As for that other thread. Notice how the OP never bothered to get back with either a "thanks, that worked great" or "tried it, but couldn't make it work".
A little courtesy on HIS part would have answered all YOUR questions.
 
Top