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 #172 background imageLoading...
Page #172 background image
Before we dive into the games code, make sure youve installed the TVout
library as described in Using the TVout Library, on page 133. You also have to
make the code of your Nunchuk library available. We havent turned it into
a complete library in this chapter, but the books code archive contains an
enhanced version. Download the books code from the books website and
unzip it. Copy the
code/Tinkering/Nunchuk
directory to the
libraries
folder of your
Arduino IDE. Alternatively, you can create a folder named
Nunchuk
in your
IDEs
libraries
folder and copy the
nunchuk.h
and
nunchuk.cpp
files to it. In both
cases you have to restart the IDE.
Thats all the preparation you need to implement the Pragduino game, so lets
get started.
Setting the Stage for the Game
Most games need to handle a lot of global state, and Pragduino is no exception,
so its code starts with a list of constant and variable definitions:
Tinkering/Pragduino/Pragduino.ino
#include <Wire.h>
#include <TVout.h>
#include <fontALL.h>
#include "nunchuk.h"
const int WIDTH = 128;
const int HEIGHT = 96;
const int CH_LEN = 8;
const int MAX_TARGET = 10;
const int TARGET_LIFESPAN = 1500;
As usual, we include all header files we need and define a few constants.
WIDTH
and
HEIGHT
contain the screen dimensions, and
CH_LEN
contains the
length of a single crosshair element. (The crosshairs consist of four elements.)
MAX_TARGET
contains the number of circles you have to shoot, and
TARGET_LIFESPAN
contains a circles lifespan measured in milliseconds.
Next we define several global variables:
Tinkering/Pragduino/Pragduino.ino
TVout tv;
Line 1
Nunchuk nunchuk;
-
-
boolean up, down, left, right, c_button, z_button;
-
int chx, chy;
5
int chvx, chvy;
-
int target_x, target_y, target_r;
-
unsigned int target_count;
-
unsigned int hits;
-
report erratum discuss
Creating Your Own Video Game 155
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