Hardware Reference
In-Depth Information
1023, but the motor control requires a value between 0 and 255. (Negative val-
ues are not used.) To adapt these values, map() is called on line 16; the result is
stored in an int called motorSpeed .
Two new variables are declared on lines 19 and 20, and default values are
assigned: 0. On line 22, the input of TinkerKit connector TK5 is read, and if
this value is true , the user instructs the left motor to operate. If so, the value
of leftMotor is set to motorSpeed , ordering the motor to turn forward. The
same thing is done with the right-side motor on line 25. Finally, the motors are
programmed on line 29 with motorsWrite() .
Now that the motors have been activated or deactivated, the sketch waits for
1/10th of a second through a delay() on line 32 before continuing.
Multiple TinkerKit connectors are available, and you can use TK6 in the same
manner to control the speaker. How about making the Arduino Robot beep on
command to tell pesky cats and humans to get out of the way?
The TinkerKit inputs are set as digital but can also be set as analog, allowing
the user to control the speed of the Arduino Robot. Change the inputs to make
them analog.
Summary
In this chapter you have seen one of the most fascinating Arduinos, the Arduino
Robot. You have seen the two boards that together make the Robot—the Control
Board and the Motor Board. You have seen the library used to control both and
how simple sketches can result in a fully functional mobile device. You have
also seen how the Arduino Robot can use external sensors to be controlled. In
the next chapter you will learn about the Arduino Yún and the Bridge library
used to exchange messages between the Arduino microcontroller and a more
powerful microprocessor running Linux.
 
Search WWH ::




Custom Search