Datasheet
Your Shield-Bot’s Brain • Chapter 1
Robotics with the BOE Shield-Bot • 37
• Documented code can save you lots of time trying to remember what your code
does, and how it does it, after you haven’t looked at it for a long time.
• In addition to making your code easier to read, constants allow you to adjust an
often-used value quickly and accurately by updating a single constant
declaration. Trying to find and update each instance of an unnamed value by
hand is an easy way to create bugs in your sketch!
Now it is your turn to give it a try, and develop a new, good habit.
Read through the sketch to see how constants and comments are used.
Open up the SimpleDecisions sketch and document it, using the sketch
CountToTenDocumented as an example.
Add a title and detailed description of the sketch, enclosed in a block comment.
Use
const declarations to name the values of 89 and 42.
Use the names from your
const declarations instead of 89 and 42 in the setup
function.
Add line comments to the right of each line.
Chapter 1 Summary
After going to the Arduino site to install and test your software and programming
connection, this chapter guided you through several programming activities. These example
sketches showed you how to make your microcontroller do some common tasks, introduced
many programming concepts, and suggested a couple of good habits to develop your
computer skills.
Microcontroller Tasks
• Sending messages to a serial monitor for display
• Storing and retrieving values from memory
• Solving math problems
• Making decisions to control program flow
• Counting and controlling repetitions
Programming Concepts
• What a function is, and how to pass a value to a function’s parameter
• What the Arduino’s
setup and loop functions do
• The difference between global and local variables
• Declaring and using variable data types, with examples of
char, int, and float
• How to solve math problems with arithmetic operators
• How to make decisions with
if, if…else, and if…else if