Help needed with code please.

Jervis

New Member
I can't understand why this code works when, for instance, w12 has value of 280 and w13 has value of 30 but doesn't work when w12=290 and w13=30.
Can someone please explain where I've gone wrong please?

Code:
#picaxe 08m2
setfreq m16

w12=280			;w12 varies but is always >180 and<361 degrees
w13=30			;w13 varies but is always <181 degrees

label1:				
let b11=w12-w13		;b11 is degrees right
if b11 >180 then gosub label2
goto label3 

label2:
let b10=360-w12+w13	;to give smallest angle between			
let b11=0			;w12 and w13 in a 360 degree circle
return			;b10 is degrees left

label3:
b9=b10+b11
 

Rick100

Senior Member
Your b11 variable can only hold a value between 0 and 255. So , '290-30 = 260' will cause it to wrap around.
 

Jervis

New Member
DOH!!!
Yes, something so obvious.
I've changed b11 to w11 and it works perfectly.
I had used a word on an earlier version but changed it to a byte to save memory- thinking that the b11 value would always be less than 181
Thankyou for your quick replies.
 
Top