Chapter 1 Challenges
Questions
- What device will be the brain of your BOE Shield-Bot?
- When the Arduino sends a character to your PC/laptop, what type of numbers are used to send the message through the programming cable?
- What is the difference between the setup and loop functions?
- What’s the difference between a variable name and a variable type?
- What’s the difference between global and local variables?
- What are the arithmetic operators? What does each one do?
- What variable type will the Arduino editor apply to 21.5 if it appears in your code? Why?
- What three elements are included between parentheses in a for loop?
- What’s the difference between a block comment and a line comment?
Exercises
- Write a piece of code that displays “the value of i = ” followed by the value of stored in the variable i in the Serial Monitor. Both should display on the same line, and then move the cursor to the beginning of the next line for displaying more messages.
- Declare a long variable named bigVal, and initialize it to 80 million.
- Write an if…else statement that takes the modulus of a variable divided by 2 and compares it to zero. If the result is zero, display “The variable is even.” If not, display “The variable is odd.”
- Write a for loop that starts counting at 21 and stops at 39, and counts in steps of 3.
- Write a piece of code that displays the character a variable stores along with its ASCII value.
- Write a for loop, but instead of counting from one value to another, make it count from ‘A’ to ‘Z’ and display the letters in the alphabet.
Projects
- Write a sketch to display the printable ASCII characters. The first printable character is the space character, which is one press/release of your keyboard’s space bar between apostrophes, like this: ‘ ’. The last printable character is the tilde character ‘~’. Alternately, you could use 32 for the loop’s start value and 126 for the end value.
- Write a sketch that tells you if a variable is odd or even. Hint: when a number is even, the remainder of the number divided by 2 is 0. Hint: variable % 2 == 0.