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 #142 background imageLoading...
Page #142 background image
we read its width. In the next line we do the same to determine the blocks
height. Because all blocks have the same width and height, we have to do
this only once. After that we determine the balls current position.
In line 38, we use the
each
method to loop over all blocks in the HTML docu-
ment.
each
expects a callback function that gets called for each block. Note
that the function doesnt get any arguments, because you can find the current
block in
$(this)
.
In the loop function, we check whether the current block is visible, because
if its not, we dont have to check it for a collision. We use our helper functions
inXRange
and
inYRange
to see whether the current block has been hit by the ball.
In that case we make it invisible, and depending on the way the ball has hit
the block, we invert the balls velocities.
Finally, we have to make sure that the
gameLoop
function is called every 30
milliseconds to make the game run smoothly:
BrowserGame/Arduinoid/js/arduinoid.js
$(function() {
initGame();
setInterval(gameLoop, 30);
});
We use yet another variant of jQuerys
$
function. This time we pass it an
anonymous function that gets called as soon as the HTML page has been
loaded completely. In this function, we initialize the game and make sure the
gameLoop
function is called every 30 milliseconds.
The game is complete, so play a few rounds and relax! You deserve it!
What If It Doesnt Work?
If you cannot make this chapters code run, you should download the code
from the books website and try to run it. Make sure youre using the right
serial port in the
arduinoid.js
and
game_controller.js
files in the
code/BrowserGame/Arduinoid/js/
directory.
Exercises
Create your own computer mouse using the ADXL335 accelerometer. It
should work in free air, and it should emit the current acceleration around
the x- and y-axes. It should also have a left button and a right button.
Write a Chrome app (or perhaps code in a programming language of your
choice?) to control a mouse pointer on the screen.
Chapter 7. Writing a Game for the Motion-Sensing Game Controller 124
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