Hardware Reference
In-Depth Information
hold the output status. They are dei ned as LOW by default, meaning that without
any modii cation, they will set the outputs LOW . On line 17, the i rst button read
is made. If the up button is pressed, both outputA and outputB are set high.
The second read, on line 20, checks to see if the left button has been pressed.
If it has, then outputB is set HIGH . If the user is also pressing on the up button,
the sketch changes the output to HIGH anyway. This is why the variables were
initially set to LOW : Reads are made to see if there is a reason to set the variable
to HIGH . If two or more conditions update the variable, that isn't a problem; the
end result is the same. A third read is made on line 23 to see if the right button
has been pressed.
Finally, the two digital outputs are updated with the contents of the variables.
loop() then repeats.
A simple sketch can turn an advanced device into a remote control, even if
there are no specii c TinkerKit output routines. By making the sketch use the
digital outputs instead of using specii c functions, you can perform more soft-
ware actions than the library alone allows. The TinkerKit outputs can be used
as digital output or PWM, but by knowing the exact pin number, you could use
these pins as serial outputs, or for other purposes.
The output of this sketch is binary only; either the outputs are on or off. With
a little bit of adjustment, this could quickly become an analog output, using the
joystick. That will require a little bit of modii cation to the example in the next
chapter as well, but you will get to that later.
You will have a remote control allowing a new device freedom of movement,
but there is one button that is not used, the down button. There is no point using
it to slow down, so why not use it to make beep noises? Just like a car horn,
warning the cat or dog to get out of the way.
Alternatively, for advanced programmers, use the Esplora's accelerometer to
control output.
Summary
In this chapter you have seen the Arduino Esplora, an interesting device with
lots of embedded electronics and a rich library to read and write the compo-
nents. You have seen the library and the different functions used to read from
and write to the different components. You have seen how easy it is to create a
project. In the next chapter, you will see the Arduino Robot and the library used
to control it, and you will be able to use the sketch presented in the chapter to
control its movement.
 
Search WWH ::




Custom Search