# Chapter 1 Solutions

#### Question Solutions

1. The Arduino module.
2. Binary numbers, that is, 0’s and 1’s.  We also saw examples of how the numbers that represent characters are ASCII codes, like 109 = ‘m’.
3. The setup function’s statements get executed once when the sketch starts.  After finishing the setup function, the sketch advances to the loop function.  Its code block gets repeated indefinitely.
4. The variable’s name is used for assignment and comparison in the sketch.  The variable’s type defines the kind and range of values it can store.
5. Global variables can be accessed and modified by any function in the sketch.  Local variables can only be accessed and modified within the block where they are declared.
6. The arithmetic operators are + add, - subtract, * multiply, / divide, and % modulus.
7. It will be treated as a float type because it has a decimal point.
8. Initialization, condition, increment.
9. A block comment starts with /* and ends with */, and allows you to write comments that span multiple lines.  A line comment starts with // and makes whatever is to its right on that particular line a comment.

#### Exercise Solutions

1. Solution:
```Serial.print("the value of i = ");
Serial.println(i);```
1. Solution:
`long bigVal = 80000000;`
1. Solution:
```if(myVar % 2 == 0)
{
Serial.println("The variable is even. ");
}
else
{
Serial.println("The variable is odd. ");
}```
1. Solution:
```for(int i = 21; i <= 39; i+=3)
{
Serial.print("i = ");
Serial.println(i);
}

```
1. Solution:
```char c = "a";
Serial.print("Character = ");
Serial.print(c);
Serial.print("   ASCII value = ");
Serial.println(c, DEC);

```
1. Solution:
`for(char c = 'A'; c <='Z'; c++){}`

#### Project Solutions

1. This sketch is a modified version of CountToTen that utilizes the solution to Exercise 5 for displaying ASCII characters.
```// Robotics with the BOE Shield - Chapter 1, Project 1

void setup()
{
Serial.begin(9600);

for(char c = ' '; c <= '~'; c++)
{
Serial.print("Character = ");
Serial.print(c);
Serial.print("   ASCII value = ");
Serial.println(c, DEC);
}
Serial.println("All done!");
}

void loop()
{
// Empty, no repeating code.
}

```
1. This sketch is a modified version of SimpleDecisions that uses a variation of the solution from Exercise 3 to display whether the variable is odd or even.
```// Robotics with the BOE Shield - Chapter 1, Project 2

void setup()
{
Serial.begin(9600);

int a = 20;

if(a % 2 == 0)
{
Serial.print("a is even");
}
else
{
Serial.print("a is odd");
}
}

void loop()
{
// Empty, no repeating code.
}

```