•
SCALE_WIDTH
and
SCALE_HEIGHT
define the width and height of the thermome-
ter’s scale.
• The variable
current_temperature
holds the last temperature we measured.
last_measurement
contains the time stamp in milliseconds when we last
measured the current temperature. We need this because we don’t want
to measure the temperature permanently, but only every few seconds.
•
TV
is an instance of the
TVout
class, and we’ll use it for accessing the TV
screen using the Arduino.
Next we define the
setup
function:
Video/TvThermometer/TvThermometer.ino
void setup() {
TV.begin(PAL, SCREEN_WIDTH, SCREEN_HEIGHT);
TV.bitmap(0, 1, thermometer);
TV.select_font(font4x6);
TV.set_cursor(20, 4);
TV.print("40");
TV.set_cursor(20, 24);
TV.print("30");
TV.set_cursor(20, 44);
TV.print("20");
TV.set_cursor(20, 64);
TV.print("10");
}
We call the
begin
method of the
TV
object. We set the analog TV standard to
PAL, and we set the screen’s width and height. If your TV set prefers NTSC,
you have to replace the first argument with
NTSC
. After that, we invoke the
bitmap
method to draw the thermometer image to the screen. Its X position is
0, and its Y position is 1.
The thermometer’s image doesn’t contain numbers next to its scale, so we
add the numbers in our program. Therefore, we have to select the font we’re
going to use by using the
select_font
method. TVout’s font capabilities are quite
impressive. It comes with three fixed-width fonts (4x6, 6x8, and 8x8 pixels)
that are sufficient for most purposes. It also supports variable-width fonts,
and it even allows you to define your own. Here we use a font that’s 4 pixels
wide and 6 pixels high. The
set_cursor
method moves the cursor to a certain
screen position, and
print
prints text to the current cursor position.
The
loop
function implements the rest of our thermometer’s business logic.
report erratum • discuss
Building a TV Thermometer • 137
www.it-ebooks.info