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 #127 background imageLoading...
Page #127 background image
void loop() {
Serial.print(get_x());
Serial.print(" ");
Serial.print(get_y());
Serial.print(" ");
Serial.print(get_z());
Serial.print(" ");
if (button.update()) {
button_pressed = button.read() == HIGH;
}
Serial.println(button_pressed == HIGH ? "1" : "0");
delay(10);
}
As in Building a Dice Game, on page 55, we use the
Bounce
class to debounce
the button. The rest of the code is pretty much standard, and the only thing
worth mentioning is that we use a 38,400 baud rate to transfer the controller
data sufficiently fast.
Compile and upload the code, open the serial terminal, and play around with
the controller. Move it, press the button sometimes, and it should output
something like the following:
324 365 396 0
325 364 397 0
325 364 397 1
325 364 397 0
325 365 397 0
325 365 397 1
326 364 397 0
A homemade game controller is nice, and you can use it for many projects.
For example, you could use it to control devices such as a robot, a marble
maze, or something similar. Its original purpose is to control games, so well
build one in the next chapter.
More Projects
If you keep your eyes open, youll quickly find many more applications for
accelerometers than you might imagine. Heres a small collection of both
commercial and free products:
report erratum discuss
More Projects 109
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