AndyGadget
Senior Member
Below is a simple snippet to sort three variables into ascending order. It's a bubble sort which works fine, but is there a more compact way to do this? It's for an 08m so can't use SWAP, which is only available on X2 and M2 chips.
Code:
#picaxe 08m
symbol Tmp = b0
symbol D1 = b6
symbol D2 = b7
symbol D3 = b8
do
readadc 1,d1
readadc 2,d2
readadc 4,d3
if d1 > d2 then
tmp = d1
d1 = d2
d2 = tmp
endif
if d2 > d3 then
tmp = d2
d2 = d3
d3 = tmp
endif
if d1 > d2 then
tmp = d1
d1 = d2
d2 = tmp
endif
wait 2
loop