EasyManuals Logo

Arduino NG User Manual

Arduino NG
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 #175 background imageLoading...
Page #175 background image
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
init_game
to set all global variables to reasonable values.
The
loop
function calls
check_controls
to read the current state of the Nunchuk.
Then it checks the games current state in a
switch
statement and delegates
its work to the function responsible for handling the current state.
In line 16,
loop
calls a function of the TVout library you havent seen before.
delay_frame
waits for the beginning of the next vertical blanking intervalthat
is, for the moment when the TV sets 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
delay_frame
. This is necessary to prevent flickering,
because it ensures that the creation of the games graphics in memory stays
in sync with the actual output on the screen.
Handling the Different Game States
Handling the games 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, PSTR("A Pragmatic Game"));
5
tv.select_font(font4x6);
-
tv.printPGM(18, 74, PSTR("Press Z-Button to Start"));
-
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 158
report erratum discuss
www.it-ebooks.info

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

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

Arduino NG Specifications

General IconGeneral
BrandArduino
ModelNG
CategoryMotherboard
LanguageEnglish

Related product manuals