EasyManuals Logo

Arduino uno User Manual

Arduino uno
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #122 background imageLoading...
Page #122 background image
void loop() {
const int x = analogRead(X_AXIS_PIN);
const int y = analogRead(Y_AXIS_PIN);
const int z = analogRead(Z_AXIS_PIN);
min_x = min(x, min_x); max_x = max(x, max_x);
min_y = min(y, min_y); max_y = max(y, max_y);
min_z = min(z, min_z); max_z = max(z, max_z);
Serial.print("x(");
Serial.print(min_x);
Serial.print("/");
Serial.print(max_x);
Serial.print("), y(");
Serial.print(min_y);
Serial.print("/");
Serial.print(max_y);
Serial.print("), z(");
Serial.print(min_z);
Serial.print("/");
Serial.print(max_z);
Serial.println(")");
}
We declare variables for the minimum and maximum values of all three axes,
and we initialize them with numbers that are definitely out of the sensors
range (-1000 and 1000). In the
loop
function, we permanently measure the
acceleration of all three axes and adjust the minimum and maximum values
accordingly.
Compile and upload the sketch, then move the breadboard with the sensor
in all directions, and then tilt it around all axes. Move it slowly, move it fast,
tilt it slowly, and tilt it fast. Be careful when moving and rotating the bread-
board that you dont accidentally loosen a connection.
After a short while, the minimum and maximum values will stabilize, and
you should get output like this:
x(247/649), y(253/647), z(278/658)
Write down these values, because well need them later, and youll probably
need them when you do your own sensor experiments.
Now lets see how to get rid of the jitter. In principle, its simple. Instead of
returning the acceleration data immediately, we collect the last readings and
return their average. This way, small changes will be ironed out. The code
looks as follows:
Chapter 6. Building a Motion-Sensing Game Controller 104
report erratum discuss
www.it-ebooks.info

Table of Contents

Other manuals for Arduino uno

Questions and Answers:

Question and Answer IconNeed help?

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

Arduino uno Specifications

General IconGeneral
Form factorArduino
CertificationRoHS, FC, CE
Processor model-
Processor frequency- MHz
Microcontroller modelATmega328
Microcontroller frequency16 MHz
DC input voltage7-12 V
Operating voltage5 V
DC current per I/O pin40 mA
Flash memory0.032 MB
Maximum internal memory- GB
SRAM (Static Random Access Memory)2 KB
EEPROM (Electrically Erasable Programmable Read-Only Memory)1 KB
Wi-FiNo
Number of analog I/O pins6
Number of digital I/O pins14
Weight and Dimensions IconWeight and Dimensions
Board dimensions53.4 x 68.6 mm

Related product manuals