'compass.bs2 Arrick Robotics www.robotics.com ' 'This routine demonstrates how to use a Dinsmore 'digital compass sensor. The compass gives 8 'directional headings (N,NE,E,SE,S,SW,W,NW). heading var byte(2) main gosub compass 'get heading. 'print heading to debug window. debug "heading = ",str heading\2,cr pause 500 'wait half a second. goto main 'keep looping. '------------------------------------------------ 'this routine returns the direction of the robot. 'the variable heading has a string that tells the 'direction of the robot. compass if in4=0 then compassn 'check if north. if in2=0 then compasss 'check if south. if in5=0 then compassw 'check if west only. compasse heading(0)="E" 'Set East. heading(1)=" " return compassw heading(0)="W" 'Set West. heading(1)=" " return compassn if in5=0 then compassnw 'West? if in3=0 then compassne 'East? heading(0)="N" 'Set North. heading(1)=" " return compasss if in5=0 then compasssw 'Also west? if in3=0 then compassse 'Also east? heading(0)="S" 'South only? heading(1)=" " return compassnw heading(0)="N" 'Set Northwest. heading(1)="W" return compassne heading(0)="N" 'Set Northeast. heading(1)="E" return compasssw heading(0)="S" 'Set Southwest. heading(1)="W" return compassse heading(0)="S" 'Set Southeast. heading(1)="E" return