Peripheral myG As Accelerometer3A @ 0 ' Set the module ID as 0 Dim g_bStatus As Byte ' Store the retrieved status values Dim g_wADx, g_wADy, g_wADz As Word ' Store the voltage values in the X, Y, and Z axes Dim g_iFx, g_iFy, g_iFz As Integer ' Store the force values in the X, Y, and Z axes Dim g_wF2D As Word ' Store the force values on the 2-D plane Dim g_wAngle As Word ' Store the angle of the force on the 2-D plane Dim g_wF3D as Word ' Store the force value in the 3-D space Dim g_wAngle1 as Word ' Store the angle between the force and the XY plane in ' the 3-D space Dim g_bAngle2 as Byte ' Store the angle between the force and the Z axis in the ' the 3-D space Dim g_bLimit as Byte ' Store the sensing values for the event Sub Main() Dim i as Byte ' Store the loop count parameter Pause 1000 myG.SetMode(0) ' Set the sensitivity mode as 0 for measuring the ' acceleration value within +/- 1.5g myG.SetRefreshFreq(3) ' Set the refresh frequency as 10 times per second myG.SetAxis2D(0) ' Set the XY plane as the 2-D plane Debug CLS Pause 1000 ' The For Loop is executed to obtain the voltage values in each axis 10 times For i=1 To 10 ' DoLoop is used to ensure obtaining the updated values Do g_bStatus = myG.GetRefreshStatus() ' Get the refresh status Loop Until g_bStatus=1 myG.GetXADVal(g_wADx) ' Get the voltage value corresponding to the acceleration ' in the X axis myG.GetYADVal(g_wADy) ' Get the voltage value corresponding to the acceleration ' in the Y axis myG.GetZADVal(g_wADz) ' Get the voltage value corresponding to the acceleration ' in the Z axis Debug "X: ", g_wADx, ", Y: ", g_wADy, ", Z: ", g_wADz, CR Next myG.GetXYZForce(g_iFx, g_iFy, g_iFz) ' Get the acceleration values in the X, Y, and Z axes myG.GetForce2D(g_wF2D, g_wAngle) ' Get the force value and angel on the XY plane myG.GetForce3D(g_wF3D, g_wAngle1, g_bAngle2) ' Get the force value and angel on the XY plane Debug "Force X: ", g_iFx, ", Y: ", g_iFy, ", Z: ", g_iFz, CR Debug "2D Force: ", g_wF2D, ", Angle: ", g_wAngle, CR Debug "3D Force: ", g_wF3D, ", Angle1: ", g_wAngle1, ", Angle2: ", g_bAngle2, CR myG.SetForceLimit2D(0, 800) ' Set the limit of the applied force on the 2-D plane as ' 800(1g) g_bLimit = 0 myG.EnableForceLimit2DEvent() ' Enable the notification event for the limit of the applied ' force on the 2-D plane. ' Execute the DoLoop till the detected 2-D applied force exceeds the limit (1g) Do Loop Until g_bLimit=1 Debug "Finish" End Sub Event myG.ForceLimitEvent2D() myG.GetForce2D(g_wF2D, g_wAngle) ' Get the force value and angel on the XY plane Debug "Event Force: ", g_wF2D, CR g_bLimit = 1 End Event