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 #176 background imageLoading...
Page #176 background image
if (z_button) {
-
init_game();
20
state = RUNNING;
-
}
-
}
-
-
void game_over() {
25
tv.clear_screen();
-
tv.select_font(font8x8);
-
tv.printPGM(28, 38, PSTR("Game Over"));
-
int x = (WIDTH - 7 * 8) / 2;
-
if (hits > 9)
30
x = (WIDTH - 8 * 8) / 2;
-
tv.printPGM(x, 50, PSTR("Hits: "));
-
tv.print(x + 6 * 8, 50, hits);
-
if (z_button) {
-
state = STARTING;
35
z_button = false;
-
delay(200);
-
}
-
}
-
40
void update_game() {
-
tv.clear_screen();
-
tv.draw_circle(target_x, target_y, target_r, WHITE);
-
move_crosshairs();
-
draw_crosshairs();
45
check_target();
-
if (target_count == MAX_TARGET + 1) {
-
state = DONE;
-
z_button = false;
-
delay(200);
50
}
-
}
-
The
intro
,
start_game
, and
game_over
functions are very similar. They print a
message to the screen, then they wait for a Z button press. If the Z button
was pressed, they move to the next state. Before they move to the next state,
they set
z_button
to false and wait for 200 milliseconds. This is necessary to
debounce the Z button.
All three functions use yet another TVout method. Look at line 3, for example.
Here we use TVouts
printPGM
method. It works like the regular
print
method,
but it reads the string to be output from the Arduinos flash memory and not
from its precious SRAM. For applications that display a lot of constant mes-
sages, this can save a lot of memory.
report erratum discuss
Creating Your Own Video Game 159
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