Hardware Reference
In-Depth Information
Create a new boolean variable called gameStarted and store false in
it.
If the start button is pressed, set gameStarted to true .
If gameStarted is true, execute the code in the block.
Using flags like this can help you structure your sketch so that you can check
for a few conditions at one time and then act on those conditions later in your
code.
char
The data type char is a byte that represents an ASCII character. ASCII is a
system from the early days of computers for translating between bytes and
characters. Typically, you'll use the char data type when you're reading the
characters that are sent to Galileo via serial (see “More Serial” on page 99 ).
Here's how to create and assign a char variable:
char letter = 'm';
When using a character in your code (for instance, when you assign it to a
variable or when you compare variable to a particular value), it will always be
between single quotation marks:
char letter = 'm';
if (letter == 'm') {
// This code will be executed
}
String Object
If you need to work with text and not just single characters, you'll want to
familiarize yourself with the String object. It's a little different from the pre-
vious data types because it's technically not a variable, but an object, much
like the Servo object in Chapter 3 . Because it's an object, it means that there
are special things a String can do that other variables cannot.
You may notice that I'm using a capital S when referring to
String objects. This is a convention to distinguish it from an
array of char s, which is considered a string (with a lower case
s ). While character arrays use less memory, they're a little bit
harder to work with than String objects.
Here's one way to make a new String object:
 
Search WWH ::




Custom Search