28x1 math bracket problem

Rudra

New Member
Hi,
Recently I brought a picaxe28x1.I was trying the following:
main:
readadc10 , 0 , w0
let w1= (w0 - w3)/5
let w3=w0
pause 5000
goto main
The program is pretty simple, but somehow the editor says there is a syntax error in let w1= (w0 - w3)/5. I tried the same program in a different way and it works:
main:
readadc10 , 0 , w0
let w1= w0-w4
let w3=w1/5
let w4=w0
pause 5000
goto main
according to the picaxe manual "On X1 and X2 parts it is possible to enclose part equations in brackets e.g.
let w1 = w2 / (b5 + 2)" . So my question is what is wrong why is bracket not working for my 28x1? why is the editor saying syntax error?
Thanks
 

hippy

Ex-Staff (retired)
Unfortunately it's one of those cases where the manuals have got ahead of the firmware; it's intended to be implemented but hasn't been yet. The revision.txt file cites this as a known restriction; "28X1 'let' mathematical equations cannot yet use brackets".

w1= (w0 - w3)/5

Because the PICAXE does maths left to right, simply removing the parenthesis will give the desired result, "w1=w0-w3/5"
 

tiscando

Senior Member
I mean, why can't we just calculate maths equations left-to-right in the real world rather than having to follow BIDMAS or BODMAS? ('real world' as in e.g. on paper)
 
Last edited:

Rudra

New Member
Thanks for the info. it solved the above mentioned problem, but there is another problem now how to do a math like;
w3=w0 - w2/5
not w3=(w0 - w2)/5
Is there a simple way to implement this also? I know it could be broken down in two steps like;
w4= w2/5
w3= w0-w4
but is there any simpler way.
Thanks
Rudra
 
Last edited:

alband

Senior Member
Replace w4 with w2 in each case. You can use one variable on both sides of a single equation.
 
Top