Hardware Reference
In-Depth Information
Saying Something: The Application Layer
Now that you've got a sense of how to make the connections between devices,
it's time to build a couple of projects to understand how to organize the data you send.
Project 1
Type Brighter
In this example, you'll control the
output of a microcontroller with key-
strokes from your computer. It's a very
simple example with minimal parts, so
you can focus on the communication.
For this project, you'll make a tiny colored lamp. You'll
be able to control the brightness and color of the lamp
by sending it commands from your computer. The
RGB LED at the heart of the lamp is actually three
LEDs in one package: one red, one green, and one blue.
They share a common cathode , or negative terminal.
Connect the cathode, which is the longest leg, to the
ground of your Arduino module, and connect the three
other legs (called the anodes , one for each color) to
pins 9, 10, and 11, as shown in Figure 2-7. Bend the
cathode leg so it will fit, but make sure it's not touching
the last leg, or it will create a short circuit.
MATERIALS
When you've got the LED on the board, drill a small
hole in the pong-pong ball, slightly larger than the LED.
Fit the ball over the LED, as shown in Figure 2-10. It will
act as a nice lampshade. If the LEDs form too harsh
a spot on the ball, you can diffuse them slightly by
sanding the top of the LED case.
» 1 RGb LED, common cathode
» 1 Arduino microcontroller module
» 1 personal computer
» All necessary converters to communicate
serially from microcontroller to computer
» 1 ping-pong ball
The Protocol
Now that you've got the circuit wired up, you need
to decide how you're going to communicate with the
microcontroller to control the LEDs. You need a com-
munications protocol. This one will be very simple:
Every application needs a communications protocol, no
matter how simple it is. Even turning on a light requires
that both the sender and receiver agree on how to say
"turn on the light."
• To choose a color of LED to control, send the first
letter of the color, in lower-case (r, g, b).
• To set the brightness for that color, send a single
digit, 0 through 9.
For example, to set red at 5, green at 3, and blue at (on
a scale from 0 to 9), you'd send:
r5g3b7
Search WWH ::




Custom Search