EasyManuals Logo

Arduino Pro Mini User Manual

Arduino Pro Mini
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 #126 background imageLoading...
Page #126 background image
Figure 20An empty Proto Shield (left), and one holding our game controller (right)
const unsigned int BUFFER_SIZE = 16;
const unsigned int BAUD_RATE = 38400;
int buffer[NUM_AXES][BUFFER_SIZE];
int buffer_pos[NUM_AXES] = { 0 };
boolean button_pressed = false;
Bounce button;
void setup() {
Serial.begin(BAUD_RATE);
pinMode(BUTTON_PIN, INPUT);
button.attach(BUTTON_PIN);
button.interval(20);
}
int get_axis(const int axis) {
delay(1);
buffer[axis][buffer_pos[axis]] = analogRead(PINS[axis]);
buffer_pos[axis] = (buffer_pos[axis] + 1) % BUFFER_SIZE;
long sum = 0;
for (unsigned int i = 0; i < BUFFER_SIZE; i++)
sum += buffer[axis][i];
return round(sum / BUFFER_SIZE);
}
int get_x() { return get_axis(0); }
int get_y() { return get_axis(1); }
int get_z() { return get_axis(2); }
Chapter 6. Building a Motion-Sensing Game Controller 108
report erratum discuss
www.it-ebooks.info

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

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

Arduino Pro Mini Specifications

General IconGeneral
BrandArduino
ModelPro Mini
CategoryMotherboard
LanguageEnglish

Related product manuals