PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Badge
04 Accelerometer
04 Check XY Rotation Angle.c
1
/*
2
Check XY Rotation Angle.c
3
For rotation, hold the badge straight up/down, and rotate it in front of
4
you as though it's a steering wheel.
5
*/
6
7
#include "
simpletools.h
"
// Include simpletools library
8
#include "
badgetools.h
"
// Include badgetools library
9
10
int
xy_rotation(
int
x
,
int
y);
// Function forward declaration
11
12
int
x
, y, degrees;
// X,Y inputs, degree output
13
14
void
main
()
// Main function
15
{
16
badge_setup
();
// Call badge setup
17
oledprint
(
"Rotation"
);
18
while
(1)
19
{
20
x
=
accel
(
AX
);
// Get x and y axes
21
y =
accel
(
AY
);
22
// Convert from xy centi-gravity
23
// to degrees of rotation.
24
degrees = xy_rotation(
x
, y);
// Function call
25
26
cursor
(0, 1);
// Display result
27
oledprint
(
"%03d deg "
, degrees);
28
29
pause
(20);
30
}
31
}
32
33
// Convert from xy centi-gravity to degrees of rotation.
34
int
xy_rotation(
int
x
,
int
y)
35
{
36
float
fpx = (
float
)
x
;
// int -> float conversions
37
float
fpy = (
float
) y;
38
39
float
fpangle = atan2(fpx, fpy);
// Arctangent(x/y)
40
fpangle *= 180.0 / PI;
// Convert to radians to degrees
41
int
angle = (int) fpangle;
// Convert float angle to int
42
if
(angle < 0) angle = 360 + angle;
// -180 to 180 -> 0 to 360
43
return
angle;
// Return angle
44
}
float
AX
#define AX
For choosing the accelerometer's x-axis. Example accel(AX) returns the component of the earth's gravi...
Definition:
badgetools.h:223
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
AY
#define AY
For choosing the accelerometer's y-axis. Example accel(AY) returns the component of the earth's gravi...
Definition:
badgetools.h:215
cursor
void cursor(int col, int row)
Position the cursor to a certain column and row for printing text on the oLED display....
Definition:
oled_cursor.c:7
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
accel
int accel(int axis)
Measures acceleration and tilt on one of 3 axes (AX, AY, or AZ) in terms of centigravity (cg) units,...
Definition:
accelerometer.c:42
main
int main(void)
Definition:
GraphicsTest.c:20
oledprint
int oledprint(const char *fmt,...)
Use to display strings on the oLED display in a manner similar to displaying combinations of strings ...
Definition:
peb_text.c:4
badge_setup
int badge_setup(void)
Set up all available badge drivers. Call this function at the start of any given program to allow acc...
Definition:
badgealpha.c:29
x
int x
Definition:
07 Box and Lines.c:13
badgetools.h
This library provides convenient functions for a variety of Parallax eBadge operations.
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17