28029 Parallax Inc, 28029 Datasheet - Page 121

KIT PARTS SMART SENSORS W/TEXT

28029

Manufacturer Part Number
28029
Description
KIT PARTS SMART SENSORS W/TEXT
Manufacturer
Parallax Inc
Datasheet

Specifications of 28029

Accessory Type
Parts Kit
Product
Microcontroller Accessories
Lead Free Status / RoHS Status
Contains lead / RoHS non-compliant
For Use With/related Products
BASIC Stamp® or Javelin Modules
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Contains lead / RoHS non-compliant
Other names
28029PAR
LOOP
' -----[ Subroutine - Arcsine ]-----------------------------------------------
' This subroutine calculates arcsine based on the y coordinate on a circle
' of radius 127.
' calling this subroutine.
Arcsine:
' -----[ Subroutine - Arccosine ]---------------------------------------------
' This subroutine calculates arccosine based on the x coordinate on a circle
' of radius 127.
' calling this subroutine.
Arccosine:
PULSIN 7, 1, y
' Scale and offset x and y-axis values to -127 to 127.
x = (x MIN 1875 MAX 3125) - 1875 ** 13369 - 127
y = (y MIN 1875 MAX 3125) - 1875 ** 13369 - 127
' Calculate and display Arcsine of x-axis measurement.
side = x
GOSUB Arcsine
DEBUG HOME, "x tilt angle = ", CLREOL, SDEC3 angle, CR
' Calculate and display Arcsine of y-axis measurement.
side = y
GOSUB Arcsine
DEBUG "y tilt angle = ", CLREOL, SDEC3 angle
PAUSE 100
GOSUB Arccosine
angle = 90 - angle
RETURN
sign = side.BIT15
side = ABS(side)
angle = 63 - (side / 2)
DO
LOOP
angle = angle */ 361
IF sign = Negative THEN angle = 180 - angle' Adjust if sign is negative.
RETURN
IF (COS angle <= side) THEN EXIT
angle = angle + 1
Set the side variable equal to your y coordinate before
Set the side variable equal to your x coordinate before
Chapter 3: Tilt with the Memsic Accelerometer · Page 109
' y-axis measurement
' Pause 1/10 second
' Repeat DO...LOOP
' Inverse sine subroutine
' Get inverse cosine
' sin(angle) = cos(90 - angle)
' Inverse cosine subroutine
' Save sign of side
' Evaluate positive side
' Initial angle approximation
' Successive approximation loop
' Done when COS angle <= side
' Keep increasing angle
' Convert brads to degrees

Related parts for 28029