' Micro: PICAXE-08M or PICAXE-18X
' input 1 [pin6] compass as reference [Ref]
' input 2 [pin5] encoder as instrument [Instr]
setfreq m8 ' serial speed 9600bps ..
start:
readadc10 1, w0 ' Compass as reference => Ref to w0
readadc10 2, w1 ' Encoder as instrument => Instr to w1
if w0<=w1 then case1 ' Res = Instr - Ref
if w0>w1 then case2 ' Res = 360 - (Ref - Instr)
goto start
case1:
w2 = w1 - w0
goto calc
case2:
w2 = 1023 - w0 + w1 ' 0/359 => 0/1023 .. with 10-bit adc ..
calc:
w3 = w2 * 30 ' 12 * 30 = 360
w3 = w3 / 32 ' 32 * 32 = 1024
w3 = w3 * 12
w4 = w3 / 32
sertxd (#w4,$0D,$0A) ' send w4 as ASCII [#w4]
' string format: [w4 CR LF]
pause 1000 ' wait 1sec
goto start
end