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 #174 background imageLoading...
Page #174 background image
hits = 0;
create_target();
}
void create_target() {
target_r = random(7, 11);
target_x = random(target_r, WIDTH - target_r);
target_y = random(target_r, HEIGHT - target_r);
target_count++;
target_creation = millis();
}
The
init_game
function sets most of the global variables to constant values.
create_target
is a bit more interesting. It creates a new target at a random
position and having a random size. Well use it later on in the game loop
whenever we need to create a new target. Note that the function ensures that
the target always stays within the screens bounds. Also, it uses the
millis
function to determine the targets creation time.
Adding the Setup and Loop Functions
Like all Arduino programs our little game needs
setup
and
loop
functions:
Tinkering/Pragduino/Pragduino.ino
void setup() {
Line 1
randomSeed(analogRead(A0));
-
tv.begin(PAL, WIDTH, HEIGHT);
-
nunchuk.initialize();
-
init_game();
5
}
-
-
void loop() {
-
check_controls();
-
switch (state) {
10
case INTRO: intro(); break;
-
case STARTING: start_game(); break;
-
case RUNNING: update_game(); break;
-
case DONE: game_over(); break;
-
}
15
tv.delay_frame(1);
-
}
-
-
void check_controls() {
-
up = down = left = right = c_button = z_button = false;
20
if (nunchuk.update())
-
{
-
if (nunchuk.joystick_x() < 70)
-
left = true;
-
if (nunchuk.joystick_x() > 150)
25
right = true;
-
report erratum discuss
Creating Your Own Video Game 157
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