@shamu,
Furthermore, the SERVOPOS command only uses a byte variable (or constant) for the data with a value from 0 to 255.
Also, even when the result is to be placed into a byte variable, the PICAXE does the maths internally at 16-bits for a single line of maths.
While the word variable may funciton, only the lower 8 bits (ie lower byte) would be sued and the upper byte is "wasted".
Therefore, your code can be:
Code:
SYMBOL Servo1 = B.1
SYMBOL Pot1 = C.1
SYMBOL PotPos = b1
SYMBOL SerPos = b2
Init:
SERVO Servo1,SerPos
Main:
READADC Pot1, PotPos
SerPos =PotPos * 150 / 255 + 75
SERVOPOS Servo1, SerPos
GOTO Main
A few further comments:
1. I gave used the [code] and [/code] tags around the program code which is good forum etiquette for more than a couple of lines of code.
Not grumbling, just letting you know these tags exist.
2. Indented the program code so only the labels are in the 1st (left most) column of each line which helps folks to read the code, particularly when you start getting many lines of code.
3. Added three more SYMBOL statements – again for consistency (you had 1) and with a bigger program listing makes changing a variable or IO pin easier when there are many instances of use.
4. The Programming Editor is not case sensitive but presentation/formatting of the program listings helps others read and understand your future bigger listings resulting in more responses. So while my personal preference only here goes:
(a) for IO pins consider a capital for the port letter (helps to differentiate between variables (ie B.1 vs b.1 vs b1)
(b) For program keywords use capitals throughout – for me at least makes it easier to identify the program commands and structure at a glance.
And for more information with respect to comment 1 above:
In case you need the information, a relatively easy way to get the [code] and [/code] markers around your program listing is:
1. click on the
Go Advanced button at the bottom right of the post/edit screen
2. select the code text in your post
3. click on the hash symbol (
#) at the right hand end of the middle row of formatting icons at the top of the post/edit window which wraps your code in the relevant [code] and [/code] markers.