28029 Parallax Inc, 28029 Datasheet - Page 116

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
Page 104 · Smart Sensors and Applications
' -----[ Constants ]----------------------------------------------------------
Negative
Positive
' -----[ Variables ]----------------------------------------------------------
sine
side
angle
sign
' -----[ Initialization ]-----------------------------------------------------
DEBUG CLS
sine = -128
' -----[ Main Routine ]-------------------------------------------------------
DO UNTIL sine = 127
LOOP
END
' -----[ 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:
sine = sine + 1
side = sine
DEBUG "sine = ", SDEC sine, "
GOSUB Arcsine
DEBUG SDEC ? angle
GOSUB Arccosine
angle = 90 - angle
RETURN
sign = side.BIT15
side = ABS(side)
angle = 63 - (side / 2)
DO
CON
CON
VAR
VAR
VAR
VAR
Set the side variable equal to your y coordinate before
Set the side variable equal to your x coordinate before
1
0
Word
Word
Word
Bit
"
' Sign - .bit15 of Word variables
' sine in circle r = 127
' trig subroutine variable
' result angle - degrees
' Sign bit
' Clear Debug Terminal
' Start y at -128
' Sweep from y = -127 to y = 127
' Increment by 1
' Set side to y
' Display sine value
' Calculate arcsine
' Display the result angle
' Repeat DO...LOOP
' End program
' 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

Related parts for 28029