PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Badge
04 Accelerometer
03 Check X Tilt Angle.c
1
/*
2
Check X Tilt Angle.c
3
The raw accelerometer measurement can be converted to tilt angle.
4
*/
5
6
#include "
simpletools.h
"
// Include simpletools library
7
#include "
badgetools.h
"
// Include badgetools library
8
9
int
tilt_angle(
int
cg);
// Function forward declaration
10
11
int
x
, degrees;
// X axis and degrees
12
13
void
main
()
// Main function
14
{
15
badge_setup
();
// Call badge setup
16
oledprint
(
" X Tilt"
);
17
while
(1)
18
{
19
x
=
accel
(
AX
);
// Raw measurement
20
// Convert from centi-gravity -> degrees.
21
degrees = tilt_angle(
x
);
// Function call
22
23
cursor
(0, 1);
// Displayed
24
oledprint
(
" %02d deg "
, degrees);
25
26
pause
(20);
// 1/50 s delay before repeat
27
}
28
}
29
30
int
tilt_angle(
int
cg)
// Centi-gravity to tilt angle
31
{
32
if
(cg > 100) cg = 100;
// Limit input to +/- 100
33
if
(cg < -100) cg = -100;
34
float
fpcg = (
float
) cg;
// Centi-gravity to floating point
35
float
fpangle = asin(fpcg/100.0);
// Calculate the arcsine
36
fpangle *= 180.0 / PI;
// Convert from radians to degrees
37
int
angle = (int) fpangle;
// Floating point back to int
38
return
angle;
// Return the angle
39
}
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
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