Arduino Uno Quick Start Manual page 175

Hide thumbs Also See for Arduino Uno:
Table of Contents

Advertisement

if
(nunchuk.joystick_y() > 150)
-
up = true;
-
if
(nunchuk.joystick_y() < 70)
-
down = true;
30
c_button = nunchuk.c_button();
-
z_button = nunchuk.z_button();
-
}
-
}
-
setup
initializes the random number generator using some noise from analog
pin A0. Then it initializes the screen and the Nunchuk, and finally it calls
to set all global variables to reasonable values.
init_game
The
loop
function calls
Then it checks the game s current state in a
its work to the function responsible for handling the current state.
In line 16,
loop
calls a function of the TVout library you haven t seen before.
delay_frame
waits for the beginning of the next vertical blanking interval—that
is, for the moment when the TV set s electron beam wanders from the bottom
of the screen back to the top. We only want to wait for the beginning of the
next frame, so we pass 1 to
because it ensures that the creation of the game s graphics in memory stays
in sync with the actual output on the screen.
Handling the Different Game States
Handling the game s different states is vital, so we define separate functions
for dealing with each game state:
Tinkering/Pragduino/Pragduino.ino
void
intro() {
Line 1
tv.select_font(font8x8);
-
tv.printPGM(28, 20, PSTR("Pragduino"));
-
tv.select_font(font6x8);
-
tv.printPGM(16, 40,
5
tv.select_font(font4x6);
-
tv.printPGM(18, 74,
-
if
(z_button) {
-
state = STARTING;
-
z_button = false;
10
delay(200);
-
}
-
}
-
-
void
start_game() {
15
tv.clear_screen();
-
tv.select_font(font8x8);
-
tv.printPGM(40, 44, PSTR("READY?"));
-
Chapter 9. Tinkering with the Wii Nunchuk
check_controls
to read the current state of the Nunchuk.
delay_frame
. This is necessary to prevent flickering,
PSTR("A Pragmatic
Game"));
PSTR("Press Z-Button to
www.it-ebooks.info
switch
statement and delegates
Start"));
158
report erratum
discuss

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Arduino Uno and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents