The Arduino Inventor's Guide (17 page)

Label the LED Holes

Flip the front cardboard piece over, and number the LEDs so you have a connection guide. Start with pin 13 in the top right and count down as you go left, as shown in
Figure 3-16
. You should finish with 5 in the lower-left corner.

FIGURE 3-16:
Labeling the back side of the LED grid

Add the LEDs

With the cardboard flat, insert the nine LEDs through from the back side. You can reuse the LEDs from your breadboard prototype or grab new ones. As you insert the LEDs, keep them aligned with the long leg on the right side to make things easier when you start wiring them to the Arduino again. You want the LEDs to fit snugly, as shown in
Figure 3-17
. If the hole is too big, you can add a dab of hot glue to secure it (but, again, keep in mind that you won’t be able to reuse the LEDs afterward).

FIGURE 3-17:
Inserting the LEDs

Assemble the Parts

Now, gather the four pieces of cardboard to be assembled. You’ll probably need craft glue or a hot glue gun to secure all of the pieces together.

First, glue one of the triangles to the base to support the front plate, as shown in
Figure 3-18
. See
Figure 3-19
for the orientation of the support triangles. Repeat this process for the other triangle piece. Give the glue some time to dry before moving on.

FIGURE 3-18:
Adding support triangles to the base

With the support triangles in place, glue the front to the base. The front should fit snugly onto the tabs of the support triangles and sit on top of the base cardboard, as shown in
Figure 3-19
. For extra strength, you may also want to add hot glue along the inside edges where the front plate connects to the base and support triangles.

FIGURE 3-19:
Adding the final piece of the project—the front

With the cardboard construction part of this project done, it’s time to wire the circuit.

Connect the Electronics

There are a lot of wires in this project, so we’ll take it one step at a time. You’ll reuse the breadboard prototype circuit you built earlier in this chapter and simply use jumper wires to connect the nine LEDs to the Arduino.

There are two ways to approach this part of the project: the nonpermanent way, which uses male-to-female jumper wires, and the permanent way, which involves soldering. We’ll cover the nonpermanent approach, but if you do want to solder the LEDs to jumper wires, refer to “
How to Solder
” on page
302
for a brief lesson before you attempt that.

If the LED legs are too long, you can snip them before attaching the jumper wires, but pay attention to which leg is positive (the long leg) and which is negative. Leave the positive leg a little longer so that you can still tell which leg is which; you could also draw a dot on the back of the box. Be sure to wear eye protection, too—when you’re trimming the legs, the little wire pieces can fly up in the air and toward your eyes!

Connect the female end of each jumper wire to one of the nine LEDs on the front plate. To keep things organized, use black wires to designate the negative side, and connect these to the shorter leg of the LED, as shown in
Figure 3-20
. You can use any color for the positive side of each LED.

FIGURE 3-20:
Connecting the LEDs with male-to-female jumper wires

Once all nine LEDs are connected to male-to-female wires, connect the other end of each jumper wire to the breadboard, following the pin labels on the back side of your project. If you left the LEDs in the breadboard, remove those first, and simply plug the jumper wires into them as shown in
Figure 3-21
.

FIGURE 3-21:
Nine LEDs connected to the breadboard with male-to-female jumper wires

Each wire connected to the negative leg of an LED (each black wire) connects to a resistor that is connected to the ground rail. Each positive wire connects to the Arduino pin written on the back of your LED array.

Once you’ve added all nine LEDs to the front of your display and completed your wiring, plug your Arduino into your computer with a USB cable. If everything is wired correctly, your display will show an alternating
X
and
O
pattern. If you have a battery pack, you can connect it as shown in
Figure 3-22
.

If the test images don’t show properly, double-check that the LEDs are plugged into the correct Arduino pins. When you see the correct patterns, take a moment to bask in the glory of your new pixel art display, but don’t stop here! When you’re ready, try making a more complicated animation.

FIGURE 3-22:
The final display with cycling
X
and
O
characters

CREATE AN LED ANIMATION

Your monitor can display any image you can draw on a 3×3 grid. An animation is just a series of images shown sequentially, so if you show a bunch of 3×3 images in a row, you’ll have a pixel art animation. We’ll show you how to design and display a spinning line.

Plan the Animation Sequence

Let’s begin by translating a spinning line into a series of images. We started with a vertical line and rotated it around the display in four separate images, as shown in
Figure 3-23
.

FIGURE 3-23:
Image progression of a spinning line

Save your program from
Listing 3-10
, and then create a new sketch. Add the
setup()
and
loop()
functions in
Listing 3-11
.

LISTING 3-11:
The
setup()
code for all nine LEDs

void
setup
()
{
  
pinMode
(13,
OUTPUT
);
  
pinMode
(12,
OUTPUT
);
  
pinMode
(11,
OUTPUT
);
  
pinMode
(10,
OUTPUT
);
  
pinMode
(9,
OUTPUT
);
  
pinMode
(8,
OUTPUT
);
  
pinMode
(7,
OUTPUT
);
  
pinMode
(6,
OUTPUT
);
  
pinMode
(5,
OUTPUT
);
}
void
loop
()
{
  
//animation function call will go here
}
//custom functions to show frames will go here

Other books

Far From Heaven by Cherrie Lynn
Just Needs Killin by Schwartz, Jinx
Sam I Am by Heather Killough-Walden
Connecting Rooms by Jayne Ann Krentz
El misterio de la Casa Aranda by Jerónimo Tristante
Mathieu by Irene Ferris