First Bytes 2013
Project Illuminate
Displaying a Message
These lights are also capable of displaying messages. If you choose,
you can program the lights to display a message and compete in the
message categories. To do this task, you would need to choose a
phrase and then program your lights to write letters to spell out that
phrase. (Be sure to follow the rules of
the competition!) As an example, these lights
are scrolling a message.
To help you, we have provided a message framework
(called message_framework and available on your USB drive).
This message framework has essentially the same files and setup as
your pattern framework, but it does differ in some important ways:
- In your pattern framework, the bulbs are addressed from 0 to 15.
This framework instead assumes that the lights are situated in a 3x5
grid with an extra bulb at the bottom right (such as the one in the
video above) and that the grid is wired as follows:
15 10 5
14 9 4
13 8 3
12 7 2
11 6 1
0
(Don't worry! We will help you get this set up correctly!) In
the framework, then, the bulbs are addressed using
their (x,y) coordinates beginning from the upper left hand
corner (this is typical for graphics in computer science) as follows:
(0,0) (1,0) (2,0)
(0,1) (1,1) (2,1)
(0,2) (1,2) (2,2)
(0,3) (1,3) (2,3)
(0,4) (1,4) (2,4)
(2,5)
Therefore, when you refer to a bulb in this framework, you will refer
to it using its (x,y) coordinate rather than its position in
the strand of lights.
-
When you programmed the patterns, you worked with the data
structure strand which was a 1D-array representing the
lights. strand was later mapped onto the live lights
using strand_mirror().
This framework has a similar setup. The grid data structure,
a 2D-array representing the lights in their new configuration, holds
the values for the lights, and then that data structure is reflected
into the live lights using grid_mirror().
Like strand, grid has some extra spots to enable
scrolling.
Additionally, this framework has another data
structure, letter. The letter data structure is
similar to grid except that it holds ints rather
than pixels. letter provides a simplified way to
set the bulbs to a particular color or to turn them off (more on how
to represent a color as an int below), and then its data is
reflected into grid which is then reflected to the live
lights. Programming of the letter data structure takes place
in the letters.cpp/h files.
- Additionally, some files in this framework vary from those in the
patterns framework. Files protocol.cpp/h have been changed to
reflect the new addressing. You should not need to change these
files. grid.cpp/h replace lights.cpp/h,
and strand_mirror() and strand_scroll() have been
replaced by grid_mirror() and grid_scroll(),
respectively. The color files have also been replaced
with colors_grid files.
-
To represent the colors as ints for the letter data
structure, the colors_grid.h file contains the following line
of code:
enum {WHITE, RED};
This line is known as an enumeration, and it simply sets up
named integer constants, so that WHITE can be used as an
integer (and, in fact, represents the value 0) and RED can
also be used as an integer (it represents 1). You can read more about
enum in C/C++
on this
web page.
In this project, the enumerated types are used to indicate the desired
color in many of the given functions. You can easily add your own
colors to this enum, so feel free to try it on your own or ask for
advice.
-
In this framework, most of your coding will be done
in letters.cpp/h. These files contain some predefined code
(some of which is explained next, but most of which are defined by
comments in the .cpp file) and define the letter data
structure.
There are two important predefined functions in this
framework: print_message() and print_letter().
print_message() displays the given message to "screen", one
letter at a time, by
calling print_letter(). print_letter() has three
letters defined for you: A, B, and C. These functions are
well-commented, so look over them carefully and be sure you understand
what they do before you begin coding. Please ask if you need help our
would like to verify your conclusions.
-
Note that the framework currently displays a message but does not
scroll it. If you would like to scroll a message (as the video
does!) grid_scroll() is provided, and both letter
and grid have extra columns.
- One final note: you'll need to reset the addressing of the lights,
and the lights are only addressed at start up. So, unplug your
lights, upload your message program, and then plug in the lights while
holding down the reset button. Voila! Your lights have the correct
addresses.
Happy Texting!
|