Hardware Reference
In-Depth Information
Preprocessor directives like #define do not get a semicolon
terminator at the end of the line.
Writing the name of the #define in all capital letters is not re-
quired, but it's a convention used by most programmers.
Practice using #defines by improving the code in Example 4-3 . The threshold
between feeling nothing and feeling a squeeze is 10. The threshold between
feeling a squeeze and saying “ouch” is 600. Try setting these up as #define
statements so it's easier to adjust the values according to your sensor.
else if
With else if , you can check for another condition if the first if condition
evaluates as false. The syntax looks like this:
if (condition A) {
execute this code if condition A is true
}
else if (condition B) {
execute this code if condition A is false
and condition B is true.
}
else {
execute this code if both condition A
and condition B are false.
}
You can chain together many else if s together and optionally you can have
an else statement at the end of the chain for code that should be executed
if all the previous conditions evaluate as false.
Going Further
Now that you've explored outputs and inputs with Galileo, you can create a
device that's interactive. Here are a few ideas for how you can apply what
you've learned in this chapter:
• Create a reaction timer game that tests how fast you can press a button
after seeing an LED turn on. The scores can be sent via serial to the
computer or displayed in an array of LEDs.
• Experiment with reading the temperature with Adafruit's tutorial on how
to use the TMP36 Temperature Sensor .
• Create a pattern memory game like Simon using LEDs and buttons.
Here are some additional resources if you'd like to learn more about and ex-
plore the concepts covered in this chapter:
 
Search WWH ::




Custom Search