Pitx-sp software guide – Kontron pITX-SP User Manual
Page 39
KTD-S0003-C
Page 35
Tri-Axis Accelerometer Example
p
ITX-SP Software Guide
gotoxy
(1,2);
sprintf (str, "Acceleration X Vector = %1.4f", resX);
if
(sign)
sprintf (str, "Acceleration X Vector = -%1.4f", resX);
printf
(str);
acc_lo = ReadReg (YAXIS_REG);
// Read Y value
acc_hi = ReadReg (YAXIS_REG+1);
acc = ((word) acc_hi * 256) + (word) acc_lo;
resY = TransformValue (acc, &sign);
gotoxy
(1,3);
sprintf (str, "Acceleration Y Vector = %1.4f", resY);
if
(sign)
sprintf (str, "Acceleration Y Vector = -%1.4f", resY);
printf
(str);
acc_lo = ReadReg (ZAXIS_REG);
// Read Z value
acc_hi = ReadReg (ZAXIS_REG+1);
acc = ((word) acc_hi * 256) + (word) acc_lo;
resZ = TransformValue (acc, &sign);
gotoxy
(1,4);
sprintf (str, "Acceleration Z Vector = %1.4f", resZ);
if
(sign)
sprintf (str, "Acceleration Z Vector = -%1.4f", resZ);
printf
(str);
acc_lo = ReadReg (COMPOSITE_REG);
// Read Comp value
acc_hi = ReadReg (COMPOSITE_REG+1);
acc = ((word) acc_hi * 256) + (word) acc_lo;
resAll = TransformValue (acc, &sign);
gotoxy
(1,5);
sprintf (str, "Acceleration Composite Vector = %1.4f", resAll);
printf
(str);
delay
(500);
if (kbhit ())
{
ch = getch ();
if (ch == ESC_CHAR)
exit
(EXIT_SUCCESS);
}
}
}