/* By Andrew Chanler - Fall 2003 Handyboard driver for using Devantech Magnetic Compass - CMPS03 refer to http://www.cs.uml.edu/~achanler/robotics/ */ #use "alc_cmps03.icb" int compass() { int x; float z; int y; float degree; x = compass_driver(0); z = ((float) ( 0x0F & x) )+( 256.0*((float) ( x >> 8) )) ; if((z < 7440.0)&&(compass_wrap)) z+=65536.0; degree = ((z - 1792.0)*360.0)/71183.0; y = (int) (degree+.5); y = y % 360; return y; } void main() { while(1) { printf("compass: %d\n",compass()); sleep(.3); } }