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 #177 background imageLoading...
Page #177 background image
To transfer the string into flash memory, we use the
PSTR
macro. It ensures
that the strings we output using
printPGM
will be copied to flash memory when
the program gets compiled.
Writing the Game Loop
The most central function of our game is
update_game
. It implements the actual
game loop and first clears the screen by calling
clear_screen
. Then it uses
draw_circle
to draw the current target.
move_crosshairs
calculates the new position
of the crosshairs depending on the players movement.
draw_crosshairs
outputs
the crosshairs to the screen.
check_target
determines the state of the current targetin other words, it checks
whether the user has hit the target, whether the target has been on the screen
for too long, or whether nothing special has happened. If all targets have been
shown already, the game is over.
To control the crosshairs, we use the following helper functions:
Tinkering/Pragduino/Pragduino.ino
void move_crosshairs() {
if (left) chx -= chvx;
if (right) chx += chvx;
if (up) chy -= chvy;
if (down) chy += chvy;
if (chx <= CH_LEN)
chx = CH_LEN + 1;
if (chx >= WIDTH - CH_LEN)
chx = WIDTH - CH_LEN - 1;
if (chy <= CH_LEN)
chy = CH_LEN + 1;
if (chy >= HEIGHT - CH_LEN)
chy = HEIGHT - CH_LEN - 1;
}
void draw_crosshairs() {
tv.draw_row(chy, chx - CH_LEN, chx - 1, WHITE);
tv.draw_row(chy, chx + 1, chx + CH_LEN, WHITE);
tv.draw_column(chx, chy - CH_LEN, chy - 1, WHITE);
tv.draw_column(chx, chy + 1, chy + CH_LEN, WHITE);
}
move_crosshairs
checks all global variables related to the current Nunchuk state.
It updates the position of the crosshairs depending on the variable values.
Then it ensures that the crosshairs stay within the screens bounds.
Chapter 9. Tinkering with the Wii Nunchuk 160
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