Download Print this page

Sparkfun Electronics RedBot Getting Started page 14

Advertisement

Another sensor provided for the RedBot is a specially designed
accelerometer
board. This board
couples a
Freescale MMA8452Q accelerometer
with a
TI PCA9306 level shifter
and is designed to
attached directly to the A4/A5 header on the RedBot. In addition to normal accelerometer data
collection, it can be used to detect bumps (as in collisions) or taps (for user input).
RedBotAccel();
The class constructor accepts no parameters; simply instantiate an object of the class and the
2
library will handle all necessary configuration. Including the I
C library provided by Arduino is not
necessary either; all that is handled by the library.
void read();
Unlike most read-type functions,
does not actually return a value. What it does is copy the
read()
most recent accelerometer values into three variables (naturally enough, named
,
and
. Those
x
y
z
values can then be easily referred to using the class object name.
void enableBump();
boolean checkBump();
void setBumpThresh(int xThresh);
These three functions allow the user to enable and check bump detection. Under normal
circumstances, the
function shouldn't be needed; the bump threshold is already set
setBumpThresh()
to a good value. Users may find it useful to increase or decrease the sensitivity level; the range for
that number is 0-127.
returns a
if a bump has been detected since the last time
was called. It
checkBump()
true
checkBump()
may be useful to call
to clear any existing bumps before attempting to detect a bump for
checkBump()
Page 14 of 19

Advertisement

loading
Need help?

Need help?

Do you have a question about the RedBot and is the answer not in the manual?