Hardware Reference
In-Depth Information
digitalWrite(greenLed, HIGH);
}
if ( (n > 8) || (n < 10) ) {
// this will be executed because n is greater than 8, even though
// it's not less than 10. With ||, only one must be true.
digitalWrite(greenLed, HIGH);
}
With that information, you can now better understand what's going on in the
if statement in Example 3-2 :
if ( brightness == 0 || brightness == 255 ) {
fadeAmount = - fadeAmount ;
}
If the value of brightness equals 0 or it equals 255, then set the value of
fadeAmount to its opposite. Essentially, when the brightness hits the maxi-
mum value (255), the sketch starts fading the LED down until it gets to its
minimum value (0). Then it reverses fadeAmount 's direction again.
Other Outputs
Output pins aren't just for blinking and fading LEDs. They can also be used
to do things like control motors, make sounds, or communicate with devices.
Serial Data Output
Sometimes you may want to have Galileo send data to your computer. Per-
haps you need help figuring out why a project isn't working (also called de-
bugging ). Or you want to send sensor data to a spreadsheet. Maybe you want
to use the Galileo as a controller for a computer game you made.
For these purposes, you can use Arduino's serial library, which is a way of
sending and receiving data between devices. For now, you're just going to
use Galileo to send serial data, but you'll learn how to receive data as well in
Chapter 5 .
The USB connection between your computer and Galileo is not only for pro-
gramming the board. It's also for serial communication. To experiment with
basic serial communication from Galileo to your computer, make a few sim-
ple modifications to the fade sketch, Example 3-2 . These changes are re-
flected in Example 3-3 .
Search WWH ::




Custom Search