No big surprises here: we define a global
Nunchuk
object and initialize it in the
setup
function. In
loop
, we call
update
to request the controller’s current status
and output all attributes to the serial port.
Compile and upload the program, and then open the serial monitor and play
around with the Nunchuk. Move the stick, move the controller, and press the
buttons, and you should see something like this:
46 109 428 394 651 1 1
49 132 414 380 656 1 0
46 161 415 390 651 1 0
46 184 429 377 648 1 0
53 199 404 337 654 1 0
53 201 406 359 643 1 0
You have successfully connected a Nunchuk controller to your Arduino. It
really isn’t rocket science, and in the next section you’ll learn how to use it
to control your own video games.
The next time you buy a new piece of hardware, try to imagine how to use it
in a different context. Often it’s easier than you think. Oh, and whenever you
create a class such as our
Nunchuk
class, consider turning your code into a
library and making it available on the Internet. (See Chapter 4, Building a
Morse Code Generator Library, on page 61, to learn how to create your own
libraries.)
Creating Your Own Video Game Console
Now that you know how to generate video output and how to control the Wii
Nunchuk, it seems natural to build your own little video game console. You
only have to combine the Nunchuk circuit and the circuit for generating the
video signal. See Figure 27, Circuit of our video game console, on page 154.
Note that you still don’t need a breadboard. Simply connect the Nunchuk to
the Arduino as shown on page 146 and connect the RCA cable as shown on
page 133. That’s all you have to do to create your own video game console.
Now let’s write some games for it.
Creating Your Own Video Game
TVout and our Nunchuk library are all we need to write entertaining games
for our video game console. In this section we’ll build Pragduino, a simple
game that demonstrates most of the skills you need to write more complex
games.
report erratum • discuss
Creating Your Own Video Game Console • 153
www.it-ebooks.info