BASIC stamp manual v2.2

BASIC Stamp Architecture – SIN, SQR
Page 108 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
Figure 4.1: 127-Unit Circle
To convert brads to degrees, multiply by 180 then divide by 128, or simply
multiply with “*/ 360”. To convert degrees to brads, multiply by 128, then
divide by 180. Here’s a small program that demonstrates the SIN and COS
operators:
degr VAR Word
brads VAR Byte
DEBUG 2, 4, 0,"ANGLE", TAB, "COS", TAB, "SIN", CR
DEBUG "DEGREES", TAB,"BRADS", TAB, "(X)", TAB,"(Y)", CR
FOR degr = 0 TO 359 STEP 45 ' Increment degrees
brads = degr * 128 / 180 ' Convert to brads
DEBUG CR, DEC3 degr, TAB, DEC3 brads, TAB ' Display angle
DEBUG SDEC COS brads, TAB, SDEC SIN brads ' Display COS & SIN
NEXT
The Square Root operator (SQR) computes the integer square root of an
unsigned 16-bit number. (The number must be unsigned since the square
root of a negative number is an ‘imaginary’ number.) Remember that most
square roots have a fractional part that the BASIC Stamp discards when
SQUARE ROOT: SQR
All
2